2016-04-16 298 views
2

使用Bootstrap。我希望顶部div根据内容和底部div来固定高度,以填充父级的剩余高度。总高度应为100%。Bootstrap - 填充列的重新调整高度

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/

+0

如果你想等高列,你应该考虑的CSS显示表/表单元格属性。如果这是您的选择,也有JavaScript解决方案。 –

回答

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; 
} 
+0

在CSS中编辑了一些东西。这是它是如何工作的: https://jsfiddle.net/eb8v57pe/5/ 谢谢! – Sakutard

+0

您应该在上述两个元素上使用'table-row',不能保证您的更改能够在任何地方正常工作。 表格和单元格总是必须伸展到表格宽度或高度,所以这个'1%'总是让你在其他行上休息,使标题的高度保持最小。 –

+0

哦,我明白了,错过了。顺便说一句,无论如何,使底部可滚动的情况下滚动溢出? – Sakutard