linear-gradient

含义

linear-gradient :是一个css的函数,它是在一条直线上平滑的过度两种以上的颜色来实现的一种线性见渐变效果,通常用于创建网页的背景、边框等等。

用法

基本用法:

```css
linear-gradient(direction,color-stop1,color-stop2,...)

direction:定义渐变方向,可以用度数(45deg)或者方向,如:top,bottom,left,right来指定。

color-stop:定义渐变中的颜色,以及每个颜色停止的位置,颜色停止是一个百分比或者长度值,

1、 指定方向 :

background:linear-gradient(to right ,blue,green) 从左到右渐变蓝色到绿色。
background:linear-gradient(to bottom right ,blue,green) 到右下角的渐变蓝色到绿色。
background:linear-gradient(45deg ,blue,green) 从45度角渐变蓝色到绿色。

2、颜色停止方向:

background:linear-gradient(to right,yellow 0%,blue 50%,red 100%)。

3、指定多个颜色:

background:linear-gradient(to right,red,orange,yellow,green,blue)。

4、使用颜色函数 rgb()和hsl(),raba()等。

background:linear-gradient(to right,rgb(255,0,0),blue,hsl(120,100%,50%))。红色饱和度1005亮度50%

5、指定形状的渐变:ellipse circle等关键词

background: radial-gradient(ellipse, red, blue)。

6、多个叠加的渐变:

 background: linear-gradient(to right, black, orange), linear-gradient(to right, orange, yellow)

练习:画一个云朵

       <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>smoothing clouds make purely in css</title>
    <style>
        body {
            background: #ccc;

        }

        .clouds {
            width: 350px;
            height: 120px;
            background: #f2f9fe;
            /* 浏览器会有兼容 */
            background: linear-gradient(top, #f2f9fe 5%, #d6f0fd 100%);
            background: -webkit-linear-gradient(top, #f2f9fe 5%, #d6f0fd 100%);
            background: -moz-linear-gradient(top, #f2f9fe 5%, #d6f0fd 100%);
            background: -ms-linear-gradient(top, #f2f9fe 5%, #d6f0fd 100%);
            background: -o-linear-gradient(top, #f2f9fe 5%, #d6f0fd 100%);
            border-radius: 100px;
            -webkit-border-radius: 100px;
            -moz-border-radius: 100px;
            position: relative;
            margin: 140px auto 20px;

        }

        .clouds :after,
        .clouds :before {
            content: '';
            position: absolute;
            background: #f2f9fe;
            z-index: -1;
            /* 放在容器的底层 */
        }

        /* 底层元素之后 画一个正方形*/
        .clouds :after {
            width: 100px;
            height: 100px;
            top: -160px;
            right: 56%;
            border-radius: 100px;
            -webkit-border-radius: 100px;
            -moz-border-radius: 100px;
        }

        /* 底层原色之前  画一个正方形*/
        .clouds :before {
            width: 180px;
            height: 180px;
            top: -200px;
            left: 40%;
            border-radius: 200px;
            -webkit-border-radius: 200px;
            -moz-border-radius: 200px;
        }

        .cloudsShadow {
            width: 350px;
            position: absolute;
            bottom: -1px;
            background: #000;
            z-index: -1;
            box-shadow: 0 0 25px 8px rgba(0, 0, 0, 0.4);
            -moz-box-shadow: 0 0 25px 8px rgba(0, 0, 0, 0.4);
            -webkit-box-shadow: 0 0 25px 8px rgba(0, 0, 0, 0.4);

            border-radius: 50%;
            -moz-border-radius: 50%;
            -webkit-border-radius: 50%;
        }
    </style>
</head>

<body>
    <div class="clouds">
        <span class="cloudsShadow"></span>
    </div>

</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值