问题:我的弹出式 div dosent 占据了整个屏幕。
Fiddle复制问题。
我有一封电子邮件弹出,其中有一个背景 div,用于在触发时“变灰”网站。问题是这个 div 只占用可见屏幕,如果用户决定滚动,他们可以看到“非灰色”站点的其余部分。
我的问题:如何强制一个 div 占据浏览器窗口的整个宽度和高度?
我制作了一个 fiddle 来简化和重现问题(请参见上文),我还在下面包含了它的代码。我试图让 div 通过绝对定位占据整个屏幕(正如许多其他 SO 答案所建议的那样),但是当存在其他 div 时,这种策略失败了。知道如何绕过它吗?
html:
<body>
<div class="other_things"></div>
<div id="full"></div>
<div class="other_things"></div>
<div class="other_things"></div>
<div class="other_things"></div>
</body>
CSS:
#full {
background: rgba(0,0,0,.6);
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.other_things {width:40em; height: 50em;}
类似问题及其答案:
最佳答案
不使用 position: absolute,而是使用 position: fixed ,它会附加到窗口而不是最近的具有非静态位置的 div。
#full {
background: rgba(0,0,0,.6);
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.other_things {width:40em; height: 50em;}
你可以在 http://jsfiddle.net/gUmPR/ 看到这个工作
关于jquery - 弹出 div 以填充整个浏览器的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20021706/