【发布时间】:2011-12-11 22:36:07
【问题描述】:
我找到了一种方法,可以通过设置min-height: 100%; 使 div 容器至少占据页面的整个高度。但是,当我添加嵌套 div 并设置 height: 100%; 时,它不会拉伸到容器的高度。有办法解决吗?
html, body {
height: 100%;
margin: 0;
}
#containment {
min-height: 100%;
background: pink;
}
#containment-shadow-left {
height: 100%;
background: aqua;
}
<div id="containment">
<div id="containment-shadow-left">
Hello World!
</div>
</div>
【问题讨论】:
-
现代解决方案:给容器
display:flex和flex-direction:column,给孩子flex:1。 -
@jackocnr 由于bug,它在任何 IE 中都不起作用,它已在 Edge 中修复。
-
@jackocnr 在 2021 年无法在 chrome 或 firefox 中使用,但在某些在线代码编辑器中可以使用