使用filter屬性來設置模糊值
效果:
css樣式:
<style type="text/css"> .cover { width: 600px; height: 300px; position: relative; text-align: center; line-height: 300px; color: #fff; margin: 20px auto; } .cover::before { content: ""; position: absolute; top: 0; left: 0; width: 600px; height: 300px; background: transparent url(Images/picture/5.jpg) center center no-repeat; filter: blur(8px); z-index: -1; background-size: cover; } </style>
HTML結構:
<body> <div class="cover"> <h2>背景模糊,文字清晰顯示</h2> </div> </body>