码迷,mamicode.com
首页 > 其他好文 > 详细

渐变背景(background)效果

时间:2017-07-22 12:08:35      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:ase   ie浏览器   之间   otto   结束   cas   mon   starty   使用方法   

chrom and Safari浏览器:

webkit核心的浏览器。使用CSS3渐变方法(css-gradient)

-webkit-gradient(type, start_point, end_point, / stop...)
-webkit-gradient(type, inner_center, inner_radius, outer_center, outer_radius, / stop...)
background: -webkit-gradient(linear,0 0,0 100%,from(#2777EC),to(#6AC1FC));

-webkit-gradient是webkit引擎对渐变的实现參数,一共同拥有五个:
第一个參数表示渐变类型(type)。能够是linear(线性渐变)或者radial(径向渐变)。
第二个參数和第三个參数,都是一对值。分别表示渐变起点和终点。这对值能够用坐标形式表示,也能够用关键值表示。比方 left top(左上角)和left bottom(左下角)。
第四个和第五个參数,各自是两个color-stop函数,color-stop函数接受两个參数。第一个表示渐变的位置。0为起点,0.5为中点,1为结束点;第二个表示该点的颜色;

Firefox浏览器:

Firefox3.6+以后版本号改进了非常多CSS,Firefox支持两种类型的CSS渐变:线性的(-moz-linear-gradient)和放射状的(-moz-radial-gradient)

线性渐变(Linear Gradients)

要创建一个线性渐变,您须要设置一个起点和一个渐变的方向(或角度),并定义起止颜色

-moz-linear-gradient( [ || ,], [, ]* )

径向渐变(Radial Gradients)

为径向渐变的语法很类似于线性渐变

-moz-radial-gradient([ || ,]?

 [ || ,]?

 , [, ]*)

background: -moz-linear-gradient(#2777EC, #6AC1FC);

-moz-linear-gradient有三个參数:
第一个參数表示线性渐变的方向,top是从上到下、left是从左到右,假设定义成left top,那就是从左上角到右下角。


第二个和第三个參数各自是起点颜色和终点颜色。

你还能够在它们之间插入很多其它的參数。表示多种颜色的渐变。

万恶的IE浏览器:

IE浏览器下渐变背景的使用须要使用IE的渐变滤镜

filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=red,endcolorstr=blue,gradientType=1)

上面的滤镜代码主要有三个參数:
依次是:startcolorstr, endcolorstr, 以及gradientType。当中gradientType=1代表横向渐变,gradientType=0代表纵向淅变;
startcolorstr=”色彩” 代表渐变渐变起始的色彩。endcolorstr=”色彩” 代表渐变结尾的色彩。

上面代码实现的是红色至蓝色的渐变。可是不含透明度变化,这是因为IE眼下尚未支持opacity属性以及RGBA颜色。要实现IE下的透明度变化,还是须要使用IE滤镜。IE的透明度滤镜功能比較强大,这样的强大反而与Firefox或是Safari浏览器下的css-gradient背景渐变的使用方法类似。比如以下的使用:

filter:alpha(opacity=100 finishopacity=0 style=1 startx=0,starty=5,finishx=90,finishy=60)

各个參数的含义例如以下:
opacity表示透明度。默认的范围是从0 到 100。他们事实上是百分比的形式。也就是说,0代表全然透明,100代表全然不透明。


finishopacity 是一个可选參数,假设想要设置渐变的透明效果,就能够使用他们来指定结束时的透明度。

范围也是0 到 100。
style用来指定透明区域的形状特征:
0 代表统一形状
1 代表线形
2 代表放射状
3 代表矩形。
startx 渐变透明效果開始处的 X坐标。
starty 渐变透明效果開始处的 Y坐标。
finishx 渐变透明效果结束处的 X坐标。


finishy 渐变透明效果结束处的 Y坐标。

Opera浏览器:

Opera新版和Firfox原理使用方法一样:

background: -o-linear-gradient(#2777EC, #6AC1FC);

整理兼容性的渐变背景效果:

技术分享

.button{
background-color: #2777EC;
border: 1px solid #0099FF;
text-transform: uppercase;
font-size: 14px;
line-height: 22px;
padding: 15px 50px;
cursor: pointer;
color: #FFF;
text-transform: none;
border-radius: 4px;
-webkit-border-radius:4px;
-moz-border-radius: 4px;
box-shadow: 1px 3px 5px #555;
-moz-box-shadow: 1px 3px 5px #555;
-webkit-box-shadow: 1px 3px 5px #555;
background: -webkit-gradient(linear,0 0,0 100%,from(#2777EC),to(#6AC1FC));
background: -moz-linear-gradient(#2777EC, #6AC1FC);
background: -o-linear-gradient(#2777EC, #6AC1FC);
background: linear-gradient(top center, #2777EC, #6AC1FC);
filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=130) progid:DXImageTransform.Microsoft.gradient(startcolorstr=‘#2777EC‘,endcolorstr=‘#6AC1FC‘,gradientType=0);
-ms-filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=130) progid:DXImageTransform.Microsoft.gradient(startcolorstr=‘#2777EC‘,endcolorstr=‘#6AC1FC‘,gradientType=0);
}
.button:active,.button:focus{
color: #000;
background: -webkit-gradient(linear, 0 0, 100% 0,from(#6AC1FC), to(#2777EC));
background: -moz-linear-gradient(#6AC1FC, #2777EC);
background: -o-linear-gradient(#6AC1FC, #2777EC);
background: linear-gradient(left center, #6AC1FC, #2777EC);
}
<input class="button" type="button" value="点击按钮" />
<a class="button" href="/">链接按钮</a>
<span class="button">点击按钮</span>

渐变背景(background)效果

标签:ase   ie浏览器   之间   otto   结束   cas   mon   starty   使用方法   

原文地址:http://www.cnblogs.com/wzjhoutai/p/7220714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!