這篇文章主要介紹了css3如何實(shí)現(xiàn)背景模糊,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的文縣網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
一、普通背景模糊
代碼:
<Style> html, body { width: 100%; height: 100%; } * { margin: 0; padding: 0; } /*背景模糊*/ .bg { width: 100%; height: 100%; position: relative; background: url("./bg.jpg") no-repeat fixed; background-size: cover; box-sizing: border-box; filter: blur(2px); z-index: 1; } .content { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 200px; height: 200px; text-align: center; z-index: 2; } </Style> </head> <body> <div class="bg"> <div class="content">背景模糊</div> </div> </body>
效果如下所示:
這樣寫會使整個div的后代模糊并且還會出現(xiàn)白邊,導(dǎo)致頁面非常不美觀,要想解決這個問題,我們可以使用偽元素,因?yàn)閭卧氐哪:炔粫桓冈氐淖哟^承。
代碼:
<Style> html, body { width: 100%; height: 100%; } * { margin: 0; padding: 0; } /*背景模糊*/ .bg { width: 100%; height: 100%; position: relative; background: url("./bg.jpg") no-repeat fixed; background-size: cover; box-sizing: border-box; z-index: 1; } .bg:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; /* 從父元素繼承 background 屬性的設(shè)置 */ background: inherit; filter: blur(2px); z-index: 2; } .content { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 200px; height: 200px; text-align: center; z-index: 3; } </Style> </head> <body> <div class="bg"> <div class="content">背景模糊</div> </div> </body>
效果如下所示:
二、背景局部模糊
上一個效果會了之后,局部模糊效果就比較簡單了。
代碼:
<Style> html, body { width: 100%; height: 100%; } * { margin: 0; padding: 0; } /*背景模糊*/ .bg { width: 100%; height: 100%; position: relative; background: url("./bg.jpg") no-repeat fixed; background-size: cover; box-sizing: border-box; z-index: 1; } .content { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 200px; height: 200px; background: inherit; z-index: 2; } .content:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; background: inherit; filter: blur(15px); /*為了模糊更明顯,調(diào)高模糊度*/ z-index: 3; } .content>div { width: 100%; height: 100%; text-align: center; line-height: 200px; position: absolute; left: 0; top: 0; z-index: 4; } </Style> </head> <body> <div class="bg"> <div class="content"> <div>背景局部模糊</div> </div> </div> </body>
效果如下圖所示:
三、背景局部清晰
代碼:
<Style> html, body { width: 100%; height: 100%; } * { margin: 0; padding: 0; } /*背景模糊*/ .bg { width: 100%; height: 100%; position: relative; background: url("./bg.jpg") no-repeat fixed; background-size: cover; box-sizing: border-box; z-index: 1; } .bg:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; background: inherit; filter: blur(5px); z-index: 2; } .content { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 200px; line-height: 200px; text-align: center; background: inherit; z-index: 3; box-shadow: 0 0 10px 6px rgba(0, 0, 0, .5); } </Style> </head> <body> <div class="bg"> <div class="content"> <div>背景局部清晰</div> </div> </div> </body>
效果如下圖所示:
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“css3如何實(shí)現(xiàn)背景模糊”這篇文章對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
當(dāng)前文章:css3如何實(shí)現(xiàn)背景模糊
瀏覽地址:http://www.rwnh.cn/article0/ggdooo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站排名、移動網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、App設(shè)計(jì)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)