css 背景圖片虛化效果

來源:互聯網
上載者:User

標籤:color   share   mod   img   html   net   背景   meta   tty   

轉載地址:http://blog.csdn.net/ohehehou/article/details/51975539

需求:一個div設定了background: url,現在需要使圖片背景模糊,div內的文字清晰顯示。

原始代碼:

<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <style type="text/css"> .content { color: #ffffff; font-size: 40px; } .bg { background: url(‘1.jpg‘); background-repeat: no-repeat; background-position: center; background-size: cover; height:600px; text-align: center; line-height: 600px; } </style></head><body><div class="bg"> <div class="content">我是內容</div></div></body></html>

原始效果: 

解決方案:內容和圖片分別置於一個div,通過css設定背景div模糊度,設定內容div絕對位置。

html代碼:

<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <style type="text/css"> .content { color: #ffffff; font-size: 40px; } .bg { background: url(‘1.jpg‘); height:600px; text-align: center; line-height: 600px; } .bg-blur { float: left; width: 100%; background-repeat: no-repeat; background-position: center; background-size: cover; -webkit-filter: blur(15px); -moz-filter: blur(15px); -o-filter: blur(15px); -ms-filter: blur(15px); filter: blur(15px); } .content-front { position:absolute; left: 10px; right: 10px; height:600px; line-height: 600px; text-align: center; } </style></head><body> <div> <div class="bg bg-blur"></div> <div class="content content-front">我是內容</div> </div></div></body></html>

 

效果: 

  註:相似的效果可以通過以上的代碼改進而來

 

css 背景圖片虛化效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.