【问题标题】:Bootstrap - Fill remaning height of a columnBootstrap - 填充列的剩余高度
【发布时间】:2016-04-16 17:36:09
【问题描述】:

使用引导程序。我希望顶部 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% 并且溢出了。这个想法也是会有几个列。

提前致谢!

小提琴:https://jsfiddle.net/eb8v57pe/4/

【问题讨论】:

  • 如果您想要等高的列,您应该查看 css 显示表格/表格单元格属性。如果您愿意,还有 javascript 解决方案。

标签: html css twitter-bootstrap


【解决方案1】:
<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;
}

【讨论】:

  • 编辑了 CSS 中的一些内容。这就是它的工作方式:jsfiddle.net/eb8v57pe/5 谢谢!
  • 您应该在两个元素上使用table-row 作为上面的代码,不能保证您的更改在任何地方都能正常工作。表格行和单元格必须始终拉伸到表格宽度或高度,因此 1% 始终让您在其他行上休息,将标题高度保持在最低要求。
  • 哦,我明白了,错过了。顺便问一下,有没有办法让底部的 div 在溢出的情况下可以滚动?