如何给背景图片加颜色遮罩

方法一:通过定位叠加(注意层级关系)

<style>
        .block {
            position: relative;
            margin: 50px auto;
            width: 700px;
            height: 450px;
        }

        .block > img {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        .block > div {
            position: absolute;
            z-index: 2;
            width: 100%;
            height: 100%;
            background-color: rgba(8, 8, 8, 0.31);
        }
    </style>
<div class="block">
    <img src="../小米/img/1.jpg" alt=""/>
    <div></div>
</div>

方法二:通过伪类元素叠加

 <style>
        *{
            width: 100%;
            height: 100%;
        }
        .block{
            position: relative;
            margin: 50px auto;
            width: 700px;
            height: 450px;
        }
        .block > img {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        .block>div:before{
            content: "";
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            top: 0;
            background-color: rgba(204, 152, 22, 0.36);
            z-index: 2;
        }
    </style>
</head>
<body>
<div class="block">
    <img src="../小米/img/1.jpg" alt=""/>
    <div></div>
</div>

方法三 正片叠底

 <style>
        *{
            width: 0;
            height: 0;
        }
        .block {
            position: relative;
            margin: 50px auto;
            width: 700px;
            height: 450px;
        }

        .block > img {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        .block > div {
            position: absolute;
            z-index: 2;
            width: 100%;
            height: 100%;
            background-color: rgba(141, 255, 236, 0.31);
            background-blend-mode: multiply;/*正片叠底*/
        }
    </style>
</head>
<body>
<div class="block">
    <img src="../小米/img/1.jpg" alt=""/>
    <div></div>
</div>

方法四 背景模糊加颜色叠加

<style>
        .block {
            position: relative;
            margin: 50px auto;
            width: 700px;
            height: 450px;
        }

        .block > img {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        .block > div {
            position: absolute;
            z-index: 2;
            width: 100%;
            height: 100%;
            background-color: rgba(255, 161, 80, 0.31);
            background-blend-mode: multiply;
            filter: blur(2px);
            overflow: hidden;
        }
    </style>
</head>
<body>
<body>
<div class="block">
    <img src="../小米/img/1.jpg" alt=""/>
    <div></div>
</div>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值