一、CSS3渐变:
CSS3渐变(gradient)可以在两个或多个指定的颜色之间显示平稳的过渡。CSS3定义了两种类型的渐变(gradient):线性渐变(linear gradient)-向下/向上/向左/向右/对角方向渐变;径向渐变(radial gradient)-由它们的中心定义。
1)、线性渐变的语法:
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
从上到下的线性渐变:
#grad {
height: 200px;
background-color: red; /* 浏览器不支持时显示 */
background-image: linear-gradient(#e66465, #9198e5);
}
从左到右的线性渐变:
#grad {
height: 200px;
background-color: red;
background-image: linear-gradient(to right, red , yellow);
}
对角线性渐变:
#grad1 {
height: 200px;
background-color: red; /* 不支持线性的时候显示 */
background-image: linear-gradient(to bottom right, red , yellow);
}
使用角度线性渐变的语法:
background-image: linear-gradient(angle, color-stop1, color-stop2);
角度是指水平线和渐变线之间的夹角。逆时针方向计算。
#grad1 {
height: 100px;
background-color: red;
background-image: linear-gradient(0deg, red, yellow);
}
#grad2 {
height: 100px;
background-color: red;
background-image: linear-gradient(90deg, red, yellow);
}
#grad3 {
height: 100px;
background-color: red;
background-image: linear-gradient(180deg, red, yellow);
}
#grad4 {
height: 100px;
background-color: red;
background-image: linear-gradient(-90deg, red, yellow);
}
使用多个颜色节点的线性渐变:
#grad1 {
height: 200px;
background-color: red;
background-image: linear-gradient(red, green, blue);
}
#grad2 {