CSS3:background渐变

今天总结渐变的问题,渐变分为线性渐变、径向渐变。呼呼,废话少说,web

线性渐变:background:linear-gradient(设置渐变形式,第一个颜色起点,中间颜色点 中间颜色的位置,结束点颜色);浏览器

Linear:渐变的类型(线性渐变);eclipse

渐变的形式:可选参数 有两种方式-一、设置旋转角度,0度表明水平从左到右,90度就是从上到下啦,从0度开始逆时针变换。ide

二、使用关键字,left表明从左到右,top表明从上到下,同理right就是从右到左,lefttop-从坐上到右下,同理leftbottom,righttop,rightbottom。firefox

中间颜色与中间颜色位置为可选参数。3d

不过要考虑浏览器的兼容,我们这样写:orm

-webkit-gradient(linear,0  0,0  100%,from(起始颜色,to(结束颜色));  /*for Safari4+,Chrome 2+*/blog

-webkit-linear-gradient(起始颜色, 结束颜色);  /*for Safari 5.1+,Chrome 10+*/ip

-moz-linear-gradient(起始颜色, 结束颜色);  /*for firefox*/ci

-o-linear-gradient(起始颜色, 结束颜色);  /*Opera*/

linear-gradient(起始颜色, 结束颜色);  /*标准属性*/

对于IE来讲是个麻烦事,老办法

Filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=’ 起始颜色’,endColorstr=” 结束颜色”);  /*IE6,IE 7*/

-ms-linear-gradient(起始颜色, 结束颜色);  /*IE8*/

<div class="content1"></div>

.content1{width:500px;height:300px;border-radius:10%;background:#ade691;
background:-webkit-linear-gradient(left,#88cfc3,#329e8c 30%,#096e5d);background:-moz-linear-gradient(left,#88cfc3,#329e8c 30%,#096e5d);background:filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#88cfc3', endColorstr='#096e5d'); /* IE6,IE7 */-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#88cfc3', endColorstr='#096e5d')";background:linear-gradient(lleft,#88cfc3,#329e8c 30%,#096e5d;float:left;}
.tit1{font-size:3em;font-weight: bold;color:#f00;}

重复性线性渐变:repeating-linear-gradient属性来代替线性渐变linear-gradient;

<div class="content2"></div>

.content2{width:500px;height:200px;
background-image: -webkit-repeating-linear-gradient(red,green 40px, orange 80px);
background-image: repeating-linear-gradient(red,green 40px, orange 80px);}

 

 

径向渐变:radial-gradient(设置渐变的中心,渐变形状 渐变大小,起始颜色值,中间颜色值 中间颜色位置,终点颜色)

渐变中心,可选参数,如30px 20px指距离左侧30px距离上侧20px,能够是像素,能够是百分比,也能够是关键字,默认为中心位置。

渐变形状,可选参数,能够取值circle或eclipse【默认】

渐变大小,可循环参数,能够取值

closest-side

指定径向渐变的半径长度为从圆心到离圆心最近的边

closest-corner

指定径向渐变的半径长度为从圆心到离圆心最近的角

farthest-side

指定径向渐变的半径长度为从圆心到离圆心最远的边

farthest-corner

指定径向渐变的半径长度为从圆心到离圆心最远的角

contain

包含,指定径向渐变的半径长度为从圆心到离圆心最近的点。类同于closest-side

cover

覆盖,指定径向渐变的半径长度为从圆心到离圆心最远的点。类同于farthest-corner

 circle farthest-corner圆形渐变,ellipse farthest-corner椭圆渐变

<div class="content3"></div>

.content3{width:500px;height:200px;
background-image: -webkit-radial-gradient(circle,hsla(120,70%,60%,.9),hsla(360,60%,60%,.9));
background-image: radial-gradient(circle,hsla(120,70%,60%,.9),hsla(360,60%,60%,.9));margin-top:20px;}

相关文章
相关标签/搜索