兼容IE与firefox的css 线性渐变(linear-gradient)

建站知识 2021-07-03 08:43www.168986.cn长沙网站建设

现行渐变
看下示例
(1)垂直渐变


(2)垂直渐变


IE系列
filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='0');
参数startColorStr起始颜色 endColorStr结束颜色 gradientType为0时代表垂直,为1时代表水平

Firefox
background: -moz-linear-gradient(, #FF0000, #F9F900);
参数、bottom垂直,left、right水平 例如时从顶部由#FF0000到#F9F900渐变,bottom时从底部由#FF0000到#F9F900渐变

Opera
background: -o-linear-gradient(,#FF0000, #F9F900);
参数、bottom垂直,left、right水平 例如时从顶部由#FF0000到#F9F900渐变,bottom时从底部由#FF0000到#F9F900渐变

webkit,如Chrome、Safari等
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FF0000), to(#F9F900));
参数linear线性, x1 x2, x3 x4 x1与x3相垂直,x2与x4相水平 from起始颜色 to结束颜色

复制代码
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>线性渐变(linear-gradient)---https://.jb51.</title>
<style type="text/css">
.test1
{
width: 200px;
height: 80px;
text-align: center;
line-height: 80px;
margin-bottom: 10px;
color: White;
font-size: 20px;
filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='0');
background: -moz-linear-gradient(, #FF0000, #F9F900);
background: -o-linear-gradient(,#FF0000, #F9F900);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FF0000), to(#F9F900));
}
.test2
{
width: 200px;
height: 80px;
text-align: center;
line-height: 80px;
margin-bottom: 10px;
color: White;
font-size: 20px;
filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='1');
background: -moz-linear-gradient(left, #FF0000, #F9F900);
background: -o-linear-gradient(left,#FF0000, #F9F900);
background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#FF0000), to(#F9F900));
}
</style>
</head>
<body>
<div class="test1">
垂直渐变
</div>
<div class="test2">
水平渐变
</div>
</body>
</html>

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by