今天小編跟大家講解下有關css3給背景圖檔加顔色遮罩的方法 ,相信小夥伴們對這個話題應該有所關注吧,小編也收集到了有關css3給背景圖檔加顔色遮罩的方法 的相關資料,希望小夥伴們看了有所幫助。
前段時間在開發中 遇到需要給背景層加顔色遮罩的項目 現在特定總結一下給背景圖層加顔色遮罩的方法。
方法一:通過定位疊加(注意層級)
.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;
}
方法二:通過僞類元素疊加
.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;(正片疊底)
.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給背景圖檔加顔色遮罩的方法 希望對大家有所幫助 如果大家有任何疑問請給我留言 小編會及時回複大家的。在此也非常感謝大家對愛蒂網站的支援!
如果你覺得本文對你有幫助 歡迎轉載 煩請注明出處 謝謝!
來源:愛蒂網
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多資訊之目的,如作者資訊标記有誤,請第一時候聯系我們修改或删除,多謝。