2012-04-12 171 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