谁能告诉我为什么绝对定位的红色 DIV 没有填满整个页面以及如何解决它?它只是填充视口(viewport)。我见过很多相同的问题,但要么这个人的代码太乱了,难怪它不起作用,要么解决方案根本不起作用。
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
<div style="position: absolute; z-index: 999; background-color: #f00; left: 0px; top: 0px; right: 0px; bottom: 0px;"></div>
最佳答案
将位置从绝对位置更改为固定位置。
<div style="position: fixed; z-index: 999; background-color: #f00; left: 0px; top: 0px; right: 0px; bottom: 0px;"></div>
关于html - 绝对定位的 DIV 填满整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18938067/