2010-09-21 68 views
0
<div id="container" style="width:300px;"> 
    <div id="leftBar" style="display: inline-block; width: 200px;"> 
     //explanding text ... bla bla bla 
    </div> 
    <div id="rightBar" style="display: inline-block; width: 100px;"> 
     //this bar has a background image that should stretch to a the left bars HEIGHT 
    </div> 
</div> 

我想用rightBar來擴展leftBar。我無法使用固定值,因爲leftBar包含長度不等的文本。 rightBar應該與leftBar的高度相等。CSS定位 - rezising div到其他div

+0

'height:100%'?我對你遇到的問題感到困惑。 – Robert 2010-09-21 23:07:02

+0

您剛更改了源代碼。你能提供你有問題的真實HTML代碼嗎?省卻麻煩。 – Strelok 2010-09-21 23:20:25

+0

Stackoverflow Pro提示:如果你有你正在尋找的答案,請勾選它旁邊的標記,將其標記爲已接受。也回到以前的問題,並將其中一些標記爲已接受。你有一個0%的接受率,這將使你很難在將來得到很好的答案:D – Strelok 2010-09-22 02:05:04

回答

1

可以稍微改變的標記,並用此HTML結束:

<div id="container"> 
    <div id="leftBar"> 
     <div id="rightBar"> 
      This is your 'rightBar' 
     </div> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p>  
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
     <p>Many paragraphs of text</p> 
    </div> 
</div>​​​ 

這個CSS:

#container { 
    width: 300px; 
    background-color: yellow; 
    overflow: hidden; 
} 

#leftBar { 
    position: relative; 
    width: 200px; 
    background-color: green; 
    padding-right: 100px; 
} 

#rightBar { 
    position: absolute; 
    top: 0; 
    right: 0; 
    bottom: 0; 
    width: 100px; 
    background-color: red; 
    *height: expression(document.getElementById('container').offsetHeight); /*ie6 hack*/ 
} 

這應該很好地工作。 Check it out.

+0

這就是解決方案,thx :-) – marius 2010-09-22 01:32:58