2012-12-12 61 views
0

我有一堆嵌套divs,中間是一些內容。我希望div的內容具有最外層div的最小高度。嵌套div的最小高度

有沒有人設法做到這一點?

Here是我想要做的一個例子,我已經把代碼放在下面。我希望#c的最小高度爲#a的高度。這應該渲染一個綠色的盒子,但它實際上是紅色的。

<div id="a"> 
    <div id="b"> 
     <div id="c"> 
      Content here 
     </div> 
    </div> 
</div> 

​​#a { height: 100px; } 
#b { min-height: 100%; background-color: red} 
#c { min-height: 100%; background-color: green} 
​ 

我並不擔心它在除了現代瀏覽器之外的其他任何東西上工作。

+1

http://jsfiddle.net/hLGbR/12/ – gearsdigital

+0

使用高度不起作用,因爲當內容長於#a時,我希望它增長 – mcfedr

+0

這不是你的問題...看看Simon Pertersen的回答並接受它。按你想要的方式工作。 – gearsdigital

回答

0

從我的理解,你的DIV#A具有固定的高度,如果他是這樣的:

嘗試使用上#a

overflow: hidden; 

這個造型和增加#B,和#C

display: inline; 

這是你的提琴應該是什麼樣子,只是測試,它的工作原理:

#a { min-height: 100px; overflow:hidden;} 
#b { min-height:100%; background-color: red; display:inline;} 
#c { min-height:100%; background-color: green; display:inline;}​ 
0

你接近:

<div id="a"> 
    <div id="b"> 
     <div id="c"> 
      Content here<br /> 
      her is more content<br /> 
      Content here<br /> 
      her is more content<br /> 
      Content here<br /> 
      her is more content<br /> 
      Content here<br /> 
      her is more content<br /> 
      Content here<br /> 
      her is more content<br /> 

     </div> 
    </div> 
</div> 

CSS:

#a { height: auto; } 
#b { min-height:100%; background-color: red} 
#c { min-height:100%; background-color: green;}​ 

FIDDLE @ gearsdigital的回答(重新編輯)