2016-04-16 299 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