由于它是一个比较新的属性,因此它在浏览器中使用时须要添加它的前缀,下面的图片是彻底支持该属性的第一个浏览器版本:web
不一样厂商的浏览器的前缀也是不同的,好比:浏览器
.header { /* Safari */ background: -webkit-linear-gradient(red, blue); /* Opera */ background: -o-linear-gradient(red, blue); /* Firefox */ background: -moz-linear-gradient(red, blue); /* 标准的语法, 放在最后 */ background: linear-gradient(red, blue); }
不一样的浏览器厂商在实现这个标准时也是略有不一样的,好比关于方向的定义,角度的定义,是顺时针仍是逆时针。ide
基本语法spa
background: linear-gradient(direction, color-stop1, color-stop2, ...);
在不添加角度和方向的前提下,默认是从上到下code
background: linear-gradient(color1, color2);
从左到右blog
to right/left/bottom/top background:linear-gradient(to right,#147B96,#E6D205);
对角(须要把两个方向相结合)图片
to right bottom/right top/left bottom/left top background:linear-gradient(to bottom right,#147B96,#E6D205);
使用角度ip
background: linear-gradient(45deg, #147B96 , transparent);
多种颜色ci
background: linear-gradient(to right, #147B96, #E6D205 25%, #147B96 50%, #E6D205 75%, #147B96); background: linear-gradient(to right, #147B96, #E6D205 50px, #147B96 50px, #E6D205 50px, #147B96);
重复渐变it
background: repeating-linear-gradient(to right, #147B96, #E6D205 5%, #147B96 10%, #E6D205 20%);
声明多个 - 逗号分隔 - 最早声明优先级最高
background: linear-gradient(green 10px, transparent 10px), linear-gradient(90deg,green 10px, transparent 10px) repeat left top / 40px, linear-gradient(transparent 40px, green 4px);
基本语法
background: radial-gradient(center, shape size, start-color, ..., last-color);
渐变中心,整个图形的中心点,既能够使用px,也能够使用%。
background-image: radial-gradient(0% 0%, red, green, blue);
渐变形状,主要是有两种:circle(圆形)和ellipse(椭圆形)
background:radial-gradient(circle, red, green, blue);
渐变大小
background:radial-gradient(circle at farthest-corner, red, green, blue);
渐变中心、渐变形状和渐变大小这三个就是径向渐变的主要使用,除此以外,也能够和线性渐变同样使用多种颜色,重复渐变以及声明多个渐变。
这篇文章主要分享了Linear Gradients(线性渐变)与Radial Gradients(径向渐变)的基本概念, 介绍了两种渐变的经常使用属性,最后结合了Linear Gradients实例介绍了CSS3渐变在实际中的部分应用场景。