欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通過css使用background-color為背景圖添加遮罩效果的兩種方法

  發(fā)布時間:2018-07-12 15:48:23   作者:佚名   我要評論
這篇文章主要介紹了通過css使用background-color為背景圖添加遮罩效果的兩種方法,需要的朋友可以參考下

一個div同時設(shè)置background-color和background-image的話,color是處于img層下方的,無法實現(xiàn)遮罩效果,所以需要再創(chuàng)建一個div作為其子div,然后設(shè)置子div的背景顏色,介紹兩種方法:

第一種,代碼如下:

css:
 

.wrap{
    position: relative;
    background: url(i/pic4.jpg) no-repeat;
    -webkit-background-size: 100%;
    background-size: 100%;
}
.warp-mask{
    height:100%;
    width:100%;
    background: rgba(0,0,0,.4);
}

html:
 

<div class="wrap">
    <div class="wrap-mask"></div>
</div>

第二種,通過after偽元素設(shè)置,代碼如下:

css:
 

.wrap{
    position: relative;
    background: url(i/pic4.jpg) no-repeat;
    -webkit-background-size: 100%;
    background-size: 100%;
}
.wrap-mask:after{
    position: absolute;
    top: 0;
    left: 0;
    content: "";
    background-color: yellow;
    opacity: 0.2;
    z-index: 1;
    width: 100%;
    height: 100%;
}

html:

<div class="wrap">
    <div class="wrap-mask"></div>
</div>

總結(jié)

以上所述是小編給大家介紹的通過css使用background-color為背景圖添加遮罩效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論