div填满所有剩余的空白区域(不是3列)

时间:2011-07-27 08:23:41

标签: html css

我有3个div叠在一起:

  • div1 20px
  • div2占用剩余屏幕高度
  • div3 20px

如何让div2占用剩余的屏幕高度?

注意:我不想使用javascript。

2 个答案:

答案 0 :(得分:3)

<div id="top"></div>
<div id="middle"></div>
<div id="bottom"></div>

#top,#bottom {
    position:absolute;
    height:20px;
    left:0;
    right:0;
}
#top { top:0; }
#bottom { bottom:0; }
#middle {
    position:absolute;
    top:20px;
    bottom:20px;
    left:0;
    right:0;
}

它应该有用。

答案 1 :(得分:1)

也许是这样的:

<div id="top">
    top div
</div>
<div id="middle">
    middle div
</div>
<div id="bottom">
    bottom div
</div>

#top {
    height: 20px;
}

#bottom {
    height: 20px;
    bottom: 0;
    position: absolute;
    width: 100%;
}

请参阅此代码: http://jsfiddle.net/PzA3W/

相关问题