【发布时间】:2016-01-29 15:48:58
【问题描述】:
这是 Bootstrap 3。我只想将我的 sidebar 分成两个部分。底部应足够高以容纳内容,而顶部应填充父级的剩余高度。以下是我用我有限的 HTML/CSS 能力所能达到的最接近的结果:
我的 HTML:
<body>
<div class="container-fluid">
<div class="sidebar col-md-3" style="background-color: lightyellow">
<div class="topClass" style="background-color: lightcoral;">
Should fill the remaining height of the parent
</div>
<div class="bottomClass" style="background-color: lightcyan;">
Should be high enough to fit its contents
A few lines of text <br />
A few lines of text <br />
A few lines of text <br />
A few lines of text <br />
</div>
</div>
</div>
</body>
我的 CSS:
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
display: block;
}
.sidebar .topClass {
position: absolute;
overflow-x: hidden;
overflow-y: auto;
position: absolute;
left: 0;
right: 0;
}
.sidebar .bottomClass {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
我在 Google 机器上看到了一个非常相似的问题,但在我的情况下,我不知道另一个 <div> 的高度,所以我认为我不能使用新的 calc 功能。
【问题讨论】:
标签: html css twitter-bootstrap layout twitter-bootstrap-3