兼容ie6.7.8.9 firefox,safari,chrome 不兼容operacss
css代码:
.gradient{
width:300px;
height:150px;
filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) progid:DXImageTransform.Microsoft.gradient(startcolorstr=red,endcolorstr=blue,gradientType=0);
-ms-filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) progid:DXImageTransform.Microsoft.gradient(startcolorstr=red,endcolorstr=blue,gradientType=0);
background:red; /* 一些不支持背景渐变的浏览器 */
background:-moz-linear-gradient(top, red, rgba(0, 0, 255, 0.5));
background:-webkit-gradient(linear, 0 0, 0 bottom, from(#ff0000), to(rgba(0, 0, 255, 0.5)));
}html
上面的滤镜代码主要有三个参数,依次是:startcolorstr, endcolorstr, 以及gradientType。
其中gradientType=1表明横向渐变,gradientType=0表明纵向淅变。startcolorstr=”色彩”
表明渐变渐变起始的色彩,endcolorstr=”色彩” 表明渐变结尾的色彩。
opacity表示透明度,默认的范围是从0 到 100,他们实际上是百分比的形式。
也就是说,0表明彻底透明,100表明彻底不透明。
finishopacity 是一个可选参数,若是想要设置渐变的透明效果,就可使用他们来指定结束时的透明度。
范围也是0 到 100。
style用来指定透明区域的形状特征:
0 表明统一形状
1 表明线形
2 表明放射状
3 表明矩形。
startx 渐变透明效果开始处的 X坐标。
starty 渐变透明效果开始处的 Y坐标。
finishx 渐变透明效果结束处的 X坐标。
finishy 渐变透明效果结束处的 Y坐标web
html代码:
<div class="gradient"></div>chrome
效果图以下:浏览器
渐变工具:ide
http://www.colorzilla.com/gradient-editor/
http://samples.msdn.microsoft.com/workshop/samples/author/filter/DropShadow.htm工具