這篇文章給大家分享的是有關css3如何給背景圖層加顏色遮罩的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

在開發中,有時遇到需要給背景層加顏色遮罩的項目,現在特定總結一下給背景圖層加顏色遮罩的方法。

方法一:通過定位疊加(注意層級)
<div class="wrap1">
<div class="inner"> </div>
</div>
.wrap1 {
position: relative;
width: 1200px;
height: 400px;
background: rgba(0, 0, 0, .5);
}
.wrap1 .inner {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: url(ban8.jpg) no-repeat center center;
background-size: cover;
z-index: -1;
}方法二:通過偽類元素疊加
<div class="wrap2"></div>
.wrap2 {
position: relative;
width: 1200px;
height: 400px;
background: url(ban8.jpg) no-repeat center center;
background-size: cover;
}
.wrap2::before {
content: "";
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background-color: rgba(0, 0, 0, .5);
z-index: 2;
}方法三:CSS3顏色疊加background-blend-mode:multiply;(正片疊底)
<div class="wrap3"></div>
.wrap3 {
position: relative;
width: 1200px;
height: 400px;
background: url(ban8.jpg) rgba(0, 0, 0, .5) no-repeat center center;
background-blend-mode: multiply;
}拓展:背景模糊加顏色疊加

.wrap4 {
position: relative;
width: 1200px;
height: 400px;
background: url(ban8.jpg) rgba(0, 0, 0, .5) no-repeat center center;
background-blend-mode: multiply;
filter: blur(2px);
overflow: hidden;
}感謝各位的閱讀!關于“css3如何給背景圖層加顏色遮罩”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
網站欄目:css3如何給背景圖層加顏色遮罩-創新互聯
分享URL:http://www.js-pz168.com/article14/dgojge.html
成都網站建設公司_創新互聯,為您提供品牌網站設計、App開發、網站排名、網站維護、網站內鏈、標簽優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯