html - Bootstrap - 填充列的剩余高度

标签 html css twitter-bootstrap

使用 Bootstrap 。我希望顶部 div 根据内容固定高度,底部 div 填充父级的剩余高度。总高度应为 100%。

HTML:

<div class="container-fluid">
  <div class="row">
    <div class="col-lg-2">
      <div id="test">
        <div>
          Fixed height according to content.
        </div>
        <div class="fill">
          Rest of the height
        </div>
      </div>
    </div>
  </div>
</div>

CSS:

html, body{
  height: 100%;
}

.container-fluid, .row, .col-lg-6, #test{
  height: 100%;
}

.fill {
  background-color: #FF0000;
  height: 100%
}

但是底部的 div 似乎恰好是 100% 并且溢出了。这个想法也是将有几个专栏。

提前致谢!

fiddle :https://jsfiddle.net/eb8v57pe/4/

最佳答案

<div class="container-fluid">
  <div class="row">
    <div class="col-lg-2">
      <div id="test">
        <div class="header">
          Fixed height according to content.
        </div>
        <div class="fill">
          Rest of the height
        </div>
      </div>
    </div>
  </div>
</div>

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');

html, body{
  height:100%;
  padding: 0;
  border: none;
  margin: 0;
}

.container-fluid, .row, .col-lg-2{
  height: 100%;
}
#test {
  display: table;
  width: 100%;
  height: 100%;
}

#test > .header {
  display: table-row;
  height: 1%;
}

#test > .fill {
  display: table-row;
  background-color: #FF0000;
}

关于html - Bootstrap - 填充列的剩余高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36667452/

相关文章:

javascript - 文本溢出 :ellipsis doesn't work in HTML select properly

twitter-bootstrap - 从 less 在 yii2 中编译自定义 Bootstrap css

html - 最好使用 Bootstrap 的 HTML/Row 类将一堆 div 包装在一个全 Angular 容器中?

php - 在 php 中处理表单的多个输入

javascript - 所有 HTML 元素的 GZIP 压缩

javascript - 回调时变量值的反转

html - 如何使用剪辑路径在多边形中组合一个圆并添加阴影

javascript - Web 应用程序中的数字本地化

css - 向右浮动和绝对位置不能一起工作

css - 使 IE9 崩溃的 Bootstrap 3 CSS 提取物