首先看一下css3有提供哪三种类型的渐变:
linear-gradient : 线性渐变
语法
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
/*线性渐变 - 从上到下(默认情况下)*/
#grad {
background-image: linear-gradient(#e66465, #9198e5);
}
/*线性渐变 - 从左到右*/
#grad {
height: 200px;
background-image: linear-gradient(to right, red , yellow);
}
/*线性渐变 - 对角*/
#grad {
height: 200px;
background-image: linear-gradient(to bottom right, red, yellow);
}
- 使用角度
#grad {
background-image: linear-gradient(-90deg, red, yellow);
}
- 使用多个颜色结点
#grad {
/* 标准的语法 */
background-image: linear-gradient(to right, red,orange,yellow,green,blue,indigo,violet);
}
- 使用透明度
#grad {
background-image: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));
}
- 重复的线性渐变
#grad {
/* 标准的语法 */
background-image: repeating-linear-gradient(red, yellow 10%, green 20%);
}
linear-gradient : 径向渐变
语法
background-image: radial-gradient(shape size at position, start-color, ..., last-color);;
/* 径向渐变 - 颜色结点均匀分布(默认情况下) */
#grad {
background-image: radial-gradient(red, yellow, green);
}
/* 径向渐变 - 颜色结点不均匀分布 */
#grad {
background-image: radial-gradient(red 5%, yellow 15%, green 60%);
}
/* 径向渐变 - 颜色结点均匀分布(默认情况下) */
#grad {
background-image: radial-gradient(red, yellow, green);
}
-
设置形状
shape 参数定义了形状。它可以是值 circle 或 ellipse。其中,circle 表示圆形,ellipse 表示椭圆形。默认值是 ellipse。
#grad {
background-image: radial-gradient(circle, red, yellow, green);
}
-
不同尺寸大小关键字的使用
size 参数定义了渐变的大小。它可以是以下四个值:
closest-side、farthest-side、closest-corner、farthest-corner
#grad1 {
background-image: radial-gradient(closest-side at 60% 55%, red, yellow, black);
}
#grad2 {
background-image: radial-gradient(farthest-side at 60% 55%, red, yellow, black);
}
- 重复的径向渐变
#grad {
background-image: repeating-radial-gradient(red, yellow 10%, green 15%);
}
conic-gradient: 圆锥渐变
.cir{
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(red, orange, yellow, green, teal, blue, purple);
}
.cir{
width:200px;
height:200px;
margin:50px auto;
background: conic-gradient(deeppink 0,deeppink 30%,yellowgreen 30%,yellowgreen 70%,teal 70%,teal 100%);
border-radius:50%;
}
菜鸟(https://www.runoob.com/css3/css3-gradients.html)
conic-gradient圆锥渐变详情(https://www.imooc.com/article/27841)