CSS 3种渐变效果(线性渐变,径向渐变,圆锥型渐变)

    科技2022-08-08  134

    1 linear-gradient(线性渐变)

    1.1按方向渐变

    语法:

    background: linear-gradient(direction, color-stop1, color-stop2, ...);

    (1)从上到下(默认)

    实现代码:

    background:linear-gradient(red , white);

    效果图:  

    (2)从左至右 

    实现代码:

    background:linear-gradient(to right, red , white);

    效果图:  

    (3)从左上角至右下角

    实现代码:

    background:linear-gradient(to bottom right, red , wihte);

    效果图: 

    (4)从右上角至左下角

    实现代码:

    background:linear-gradient(to bottom left, red , wihte);

    效果图: 

     

    1.2 按角度渐变 

    如果你想要在渐变的方向上做更多的控制,你可以定义一个角度,而不用预定义方向(to bottom、to top、to right、to left、to bottom right,等等)。

    角度是指水平线和渐变线之间的角度,逆时针方向计算。换句话说,0deg 将创建一个从下到上的渐变,90deg 将创建一个从左到右的渐变。

     

    语法:background: linear-gradient(angle, color-stop1, color-stop2);

    示例:

    从右至左渐变

    background: linear-gradient(-90deg, red, white);

    2 radial-gradient(径向渐变)

    径向渐变由它的中心定义。

    为了创建一个径向渐变,你也必须至少定义两种颜色节点。颜色节点即你想要呈现平稳过渡的颜色。同时,你也可以指定渐变的中心、形状(圆形或椭圆形)、大小。默认情况下,渐变的中心是 center(表示在中心点),渐变的形状是 ellipse(表示椭圆形),渐变的大小是 farthest-corner(表示到最远的角落)。

    语法:background: radial-gradient(shape size at position, start-color, ..., last-color);

    示例:

    background:radial-gradient(red , wihte);

    效果图: 

     

    3 conic-gradient(圆锥型渐变)

    语法:background: conic-gradient(start-color, ..., last-color);

    示例:

    background:conic-gradient(red , yellow,green,red);

    效果图: 

    Processed: 0.011, SQL: 9