2015-06-05 167 views
0

我正在編寫一個網頁,我需要一個包含兩個div(一個工具欄和一個編輯器)的div包裝器。工具欄heigth是未知的,我需要使編輯器div填充包裝中的所有剩餘空間。填寫所有剩餘空間

該解決方案需要完整的HTML + CSS。

<div id="wrapper"> 
    <div id="toolbar"> 
    </div> 
    <div id="editor"> 
    </div> 
</div> 

對於CSS:

#wrapper { 
    position: absolute; // I need this, I can't remove it 
    top: 0; // should stick on the top 
    height: 100%; // should span across the whole height 
    width: 100%; // Can be anything 0 ≤ width ≤ 100% 
} 

#editor { 
    width: 100%; // fill the whole horizontal space 
    height: 100%; // if I do so, the div gets too high and the #editor goes beyond the wrapper limit 
} 

這裏有一個jsfidlle與http://jsfiddle.net/o3hqyxxu/

+0

我分叉它。我認爲這更好地顯示你的問題:http://jsfiddle.net/3du3w9r6/ – Jakar

+0

我發現瞭解決方案http://stackoverflow.com/questions/90178/make-a-div-fill-the-height-of-剩餘的屏幕空間?rq = 1使用flexboxes。 – cphyc

回答

0

一種選擇打被設置的div表和錶行的顯示:

#wrapper { 
 
    position: absolute; 
 
    top:0; 
 
    height: 100%; 
 
    width: 70%; 
 
    display:table; 
 
} 
 
#a { 
 
    background-color: grey; 
 
    width: 100%: 
 
} 
 
#b { 
 
    background-color: lightblue; 
 
    height: 100%; 
 
    width: 100%; 
 
} 
 
#a, #b { 
 
    display:table-row; 
 
}
<div id='wrapper'> 
 
    <div id='a'>Some content that is long enough to fill a full line an even more, so you need to go back to the next line, … Ok, I think that is enough. If you have a wider screen, append text there :)</div> 
 
    <div id='b'>I want this div to fill all the empty save, not more.</div> 
 
</div>

0

如果我理解的很好,如果您在#editor上使用height:auto;而不是height:100%,它似乎對我有用。

0

我使用彈性盒找到了答案的解決方案(請參見the mdn documentation)。

這個想法是使用容器的css描述符display: flexflex-flow: row以及工具欄/編輯器的描述符flex: 0 1 auto

有一個解決方案jsfiddle here