2012-04-12 151 views

回答

3

這裏是Jsfiddle

類似這樣的標記:

​<div id="main-menu"></div> 
<div id="other-div"> 
    <h1>Sample Content</h1> 
    <p> 
     foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar 
    </p> 
</div>​ 

的CSS是這樣的:

​#other-div { 
    background: #cdcdcd; 
}​ 

的Javascript這樣的:

$('#main-menu').height($(window).height()-$("#other-div").height());​ 

從腳本中可以看到,我稱之爲高度函數。

+0

那麼,該div的高度是不固定的,它是基於內容不是它。 – CoreyRS 2012-04-12 19:42:25

+0

已編輯。 JavaScript仍然有效。 – 2012-04-12 19:45:15

+0

歡呼雀躍! – CoreyRS 2012-04-12 19:48:25