CSS3 渐变(gradients)可以在两个或多个指定的颜色之间显示平稳的过渡。
CSS3 定义了两种类型的渐变(gradients):
线性渐变(Linear Gradients)- 向下/向上/向左/向右/对角方向
径向渐变(Radial Gradients)- 由它们的中心定义
线性渐变 - 从上到下(默认情况下)
.view11 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(red, blue);}
线性渐变 - 从左到右
.view12 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(to right, red , blue);}
线性渐变 - 对角
.view13 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(to bottom right, red , blue);}
带有指定的角度的线性渐变
.view14 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(120deg, red, blue);}
带有多个颜色结点的从上到下的线性渐变
.view15 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(red, green, blue);}
带有彩虹颜色和文本的线性渐变
.view16 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(to right, red,orange,yellow,green,blue,indigo,violet);}
从左到右的线性渐变,带有透明度
.view17 {width: 240px;height: 60px;margin: 10px auto;background: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));}
repeating-linear-gradient() 函数用于重复线性渐变
.view18 {width: 240px;height: 60px;margin: 10px auto;background: repeating-linear-gradient(red, yellow 10%, green 20%);}
径向渐变 - 颜色结点均匀分布(默认情况下)
.view21 {width: 120px;height: 120px;margin: 10px auto;background: radial-gradient(red, green, blue);}
径向渐变 - 颜色结点不均匀分布
.view22 {width: 120px;height: 120px;margin: 10px auto;background: radial-gradient(red 5%, green 15%, blue 60%);}
形状为圆形的径向渐变
.view23 {width: 120px;height: 120px;margin: 10px auto;background: radial-gradient(circle, red, yellow, green);}
repeating-radial-gradient() 函数用于重复径向渐变
.view26 {width: 120px;height: 120px;margin: 10px auto;background: repeating-radial-gradient(red, yellow 10%, green 15%);}