DIV+CSS 填满剩余页面的方法

我们在做美工时,重要元素定位放好后,其他辅助元素需要铺满剩余空间,这时该怎么办呢?

这里用两个DIV模拟一下,”nav”在页面顶端占据50px高,要求”content”填满剩下空间。来看看代码:

<style type="text/css">
html, body {
    height: 100%;
    margin: 0px;
    padding: 0px;
}
#main {
    background-color: #999;
    height: 100%;
} 
#nav {
    background-color: #85d989;
    width: 100%;
    height: 50px;
}
#content {
    background-color: #cc85d9;
    width: 100%;
    position: absolute;
    top: 50px;
    bottom: 0px;
    left: 0px;
}
</style>
<div id="main">
    <div id="nav">nav</div>
    <div id="content">content</div>
</div>

由于这是全页面效果,我们就不演示啦,大家可以直接复制代码自行查看。