CSS3 漸變

div{
    width: 200px;
    height: 200px;
    background-image:repeating-linear-gradient(to right, red 10%, green 20%);
}

 

漸變分爲線性漸變徑向漸變兩種;其中:線性漸變指的是從上/下/左/右/對角方向開始的漸變,徑向漸變指的是從模塊的中心到周邊開始的漸變ide

  線性漸變:spa

  1. 從上至下線性漸變
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(#e66465, #9198e5);
    }
  2. 從左至右線性漸變
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(to right, red, yellow);
    }

     

  3. 對角線性漸變
    div{
        width: 200px;
        height: 200px;
        background-image:linear-gradient(to right bottom, red, green);
    }

     

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

     

  5. 使用多個顏色節點的線性漸變
    div{
        width: 600px;
        height: 100px;
        background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
    }

     

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

     

  7. 重複的線性漸變
    div{
        width: 200px;
        height: 200px;
        background-image:repeating-linear-gradient(to right, red 10%, green 20%);
    }

     

  徑向漸變:3d

  1. 顏色節點均勻分佈(默認狀況下)
    div{
        width: 200px;
        height: 100px;
        background-image:radial-gradient(red, yellow,green);
    }

     

  2. 顏色節點不均勻分佈
    div{
        width: 200px;
        height: 100px;
        background-image: radial-gradient(red 5%, yellow 15%, green 60%);
    }

     

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

     

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

     

  5. 重複的徑向漸變
    div{
        width: 200px;
        height: 200px;
        background-image:repeating-radial-gradient(red, yellow 10%, green 15%);
    }
  6. 不一樣尺寸大小關鍵字的使用
    .one{
        width: 100px;
        height: 100px;
        background-image:radial-gradient(closest-side at 60% 55%, red, yellow, black);
    }

     

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

     

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

     

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

 

 注:本文僅供理解,重點在於熟練使用code

相關文章
相關標籤/搜索