【发布时间】:2011-02-20 14:10:15
【问题描述】:
所以我有一个我认为很常见的问题,但我还没有找到一个好的解决方案。我想让一个覆盖 div 覆盖整个页面......不仅仅是视口。我不明白为什么这很难做到……我尝试将正文、html 高度设置为 100% 等,但这不起作用。这是我目前所拥有的:
<html>
<head>
<style type="text/css">
.OverLay { position: absolute; z-index: 3; opacity: 0.5; filter: alpha(opacity = 50); top: 0; bottom: 0; left: 0; right: 0; width: 100%; height: 100%; background-color: Black; color: White;}
body { height: 100%; }
html { height: 100%; }
</style>
</head>
<body>
<div style="height: 100%; width: 100%; position: relative;">
<div style="height: 100px; width: 300px; background-color: Red;">
</div>
<div style="height: 230px; width: 9000px; background-color: Green;">
</div>
<div style="height: 900px; width: 200px; background-color: Blue;"></div>
<div class="OverLay">TestTest!</div>
</div>
</body>
</html>
如果存在 JavaScript 解决方案,我也愿意接受,但我更愿意只使用一些简单的 CSS。
【问题讨论】:
-
还可以在这里阅读更多内容:stackoverflow.com/questions/1938536/…
-
这可以用 jQuery 实现吗?