學習自 《CSS揭秘》
這個是全部代碼:
body,main::before{ background: url("圖片路徑") 0 / cover fixed; } main{ position: relative; background: hska(0,0%,100%,.3); overflow: hidden; } main::before{ content: '', position: absolute; top:0;right:0;bottom:0;left:0; filter: blur(20px); margin:-30px; }
他的思路是: 我們不能直接對元素本身進行模糊處理,就對一個偽元素進行處理,然后將其定位到元素的下層,它的背景將會無縫匹配body的背景。margin-20px是用來擴大邊距,因為模糊會在邊緣減弱。
效果圖: