欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CSS3 渐变

程序员文章站 2022-03-26 12:21:42
div{ width: 200px; height: 200px; background-image:repeating-linear-gradient(to right, red 10%, green 20%); } 渐变分为线性渐变和径向渐变两种;其中:线性渐变指的是从上/下/左/右/对角方向开 ......
div{
    width: 200px;
    height: 200px;
    background-image:repeating-linear-gradient(to right, red 10%, green 20%);
}

 

渐变分为线性渐变径向渐变两种;其中:线性渐变指的是从上/下/左/右/对角方向开始的渐变CSS3 渐变,径向渐变指的是从模块的中心到周边开始的渐变CSS3 渐变

  线性渐变:

  1. 从上至下线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(#e66465, #9198e5);
    }
  2. 从左至右线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(to right, red, yellow);
    }

     

  3. 对角线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(to right bottom, red, green);
    }

     

  4. 使用角度的线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(-90deg, red,yellow);
    }

     

  5. 使用多个颜色节点的线性渐变CSS3 渐变
    div{
        width: 600px;
        height: 100px;
        background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
    }

     

  6. 使用透明度的线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));
    }

     

  7. 重复的线性渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:repeating-linear-gradient(to right, red 10%, green 20%);
    }

     

  径向渐变:

  1. 颜色节点均匀分布(默认情况下)CSS3 渐变
    div{
        width: 200px;
        height: 100px;
        background-image:radial-gradient(red, yellow,green);
    }

     

  2. 颜色节点不均匀分布CSS3 渐变
    div{
        width: 200px;
        height: 100px;
        background-image: radial-gradient(red 5%, yellow 15%, green 60%);
    }

     

  3. 设置形状——circleCSS3 渐变
    div{
        display: inline-block;
        width: 200px;
        height: 100px;
        background-image: radial-gradient(circle,red,yellow,green);
    }

     

  4. 设置形状——ellipseCSS3 渐变
    div{
        display: inline-block;
        width: 200px;
        height: 100px;
        background-image: radial-gradient(ellipse,red,yellow,green);
    }

     

  5. 重复的径向渐变CSS3 渐变
    div{
        width: 200px;
        height: 200px;
        background-image:repeating-radial-gradient(red, yellow 10%, green 15%);
    }
  6. 不同尺寸大小关键字的使用CSS3 渐变
    .one{
        width: 100px;
        height: 100px;
        background-image:radial-gradient(closest-side at 60% 55%, red, yellow, black);
    }

     

    CSS3 渐变
    .two{
        width: 100px;
        height: 100px;
        background-image:radial-gradient(farthest-side at 60% 55%, red, yellow, black);
    }

     

    CSS3 渐变
    .three{
        width: 100px;
        height: 100px;
        background-image:radial-gradient(closest-corner at 60% 55%, red, yellow, black);
    }

     

    CSS3 渐变
    .four{
        width: 100px;
        height: 100px;
        background-image:radial-gradient(farthest-corner at 60% 55%, red, yellow, black);
    }

 

 注:本文仅供理解,重点在于熟练使用