【发布时间】:2022-04-12 00:48:55
【问题描述】:
我在一个高度为 100% 的容器 (.container) 中有三个子元素 (.inner)。之后,我有另一个 div (.post) 没有被推到容器下面。
这是一个小提琴http://jsfiddle.net/yVDXQ/526/
HTML:
<html>
<body>
<div class="container">
<div class="inner">Inner1</div>
<div class="inner">Inner2</div>
<div class="inner">Inner3</div>
</div>
<div class="post">Some content</div>
</body>
</html>
CSS:
html {
height: 100%;
}
body {
background: red;
height: 100%;
}
.container {
background: yellow;
height: 100%;
width: 50%;
margin: 0 auto;
}
.inner{
height:100%;
background:blue;
border:1px solid #fff;
}
.post{
height:300px;
width:50%;
background: green;
}
大部分内容将在 Wordpress 中动态生成,因此我没有想要的控制权。
到目前为止,我发现并且想要避免的选择是:
在 .container 上将溢出设置为自动,这会起作用,但会给我一个滚动条,留下两个滚动条(body 和 .container)
使用JS设置.container的真实高度
还有其他方法吗?
谢谢
【问题讨论】: