HTML背景线性渐变效果,使用background-image:linear-gradient()来实现

效果图:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 200px;
            border: 1px solid black;
            float: left;
            margin-left: 5px;
            font-size: 30px;
        }
        .box1{
            background-image: linear-gradient(red,yellow,green);
        }
        .box2{
            background-image: linear-gradient( to right ,red,yellow,green);
        }
        .box21{
            background-image: linear-gradient(to right top,red,yellow,green);
        }
        .box3{
            background-image: linear-gradient(20deg,red,yellow,green);
        }
        .box4{
            background-image: linear-gradient(red 50px,yellow 100px,green 150px);
        }
        .box5{
            background-image: linear-gradient(red,green);
            text-align: center;
            line-height: 200px;
            font-size: 30px;
           font-weight: bold;  /*加粗*/
           /* 使文字透明 */
            color: transparent;
            /* 使背景呈现在文字上 */
            background-clip: text;
          
        }
    </style>
</head>
<body>
    <!-- 线性渐变 -->
    <div class="box box1">默认情况(从上至下)</div>
    <div class="box box2">(从左向右)</div>
    <div class="box box21">(从左向上)</div>
    <div class="box box3">以中间基线为角度的20度角旋转的来</div>
    <div class="box box4">50px 前必须为纯红,100px 为纯黄 。红黄之间渐变。150px为纯绿</div>
    <div class="box box5">背景呈现在文字上</div>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值