css 實現div半透明度實現代碼

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<!DOCTYPE html> <html> <head> <meta charset="gb2312" /> <title>背景半透明覆蓋整個可視地區</title> <style> html,body{ height:100%; margin:0; padding:0; font-size:14px;} p{ line-height:18px;} .mask{height:100%; width:100%; position:fixed; _position:absolute; top:0; z-index:1000; } .opacity{ opacity:0.3; filter: alpha(opacity=30); background-color:#000; } .content{height:600px; width:800px; overflow:auto; border:2px solid #ccc; background-color:#fff; position:absolute; top:50%; left:50%; margin:-300px auto auto -400px; z-index:1001; word-wrap: break-word; padding:3px;} .ph{ height:1000px;} </style> </head> <body> <p class="ph">place holder height:1000px;</p> <div class="mask opacity"></div> <div class="content"> <h1>背景半透明覆蓋整個可視地區</h1> <p> 這個效果效果在工作中經常會遇到,這篇文章主要介紹了當內容超過一屏時如何做到多瀏覽器的相容性。 下面我們通過一個簡單的例子看看如何?,高手請繞道。 </p> <p>html代碼很簡單 < d i v class="mask opacity">< / d i v > </p> <p> 1 、半透明效果可以使用 css3 中的 opacity 屬性,在低版本的IE瀏覽器中使用IE的alpha 濾鏡。代碼: <code>.opacity{ opacity:0.3; filter: alpha(opacity=30); background-color:#000; }</code> </p> <p> 2 、要覆蓋整個可視地區通常的做法是: <br/> <code> html,body{ height:100%} </code> <br/> <code>.mask{height:100%;width:100%;}</code> <br/> 但是這樣做當內容超過一屏時只有IE6下顯示的效果是我們所期望的,在其他瀏覽器中首屏以下的沒能被遮蓋住,為了相容其他瀏覽器我們可以使用<code>position:fixed; </code>來解決這個問題 </p> <p> <strong>完整的代碼</strong>: <pre> html,body{ height:100%; margin:0; padding:0} .mask{height:100%; width:100%; position:fixed; _position:absolute; top:0; z-index:1000; } .opacity{ opacity:0.3; filter: alpha(opacity=30); background-color:#000; } </pre> </p> <p> <strong>參考資料:</strong>背景半透明最佳實務垂直置中的幾種實現方法DIV 高度100%</p> </div> </body> </html> </td> </tr></table>
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.