CSS實現遮蓋層

來源:互聯網
上載者:User

大部分遮蓋層都是通過JS去擷取高度和寬度來定位的,而現在採用的大部分是CSS去做,除了一個為了相容IE6所必要的js。

大致原理就是:讓遮蓋層的height和width達到100%來去實現,IE6下需要將body的height設為100%才有效。

具體的代碼如下:

<!doctype html><html><head><title>CSS 實現遮蓋層</title><meta charset="gb2312" /><style>/* the style for layer or mask */body{_height:100%;}#mask, #undermask{display: none;position:fixed;_position:absolute;top: 0;left: 0;width: 100%;height: 100%;z-index: 33;background-color: #101010;filter: Alpha(opacity=40);opacity: .4;}/* page show */#page{width:960px;margin:0 auto;height:1000px;text-align:center;background-color:#c00;}</style></head><body><div id="page">)))))))))))))CSS 實現遮蓋層測試(((((((((((((((</div><div id="mask"></div><script>(function(mask){// for IE 6if(document.uniqueID && !window.XMLHttpRequest){document.getElementsByTagName('html')[0].style.overflow = 'hidden';}mask.style.display = 'block';})(document.getElementById('mask'));</script></body></html>

就是這樣,很簡單明了。

相關文章

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.