Two vertical divs within a 100% height div

早过忘川 提交于 2019-12-01 18:44:08

Use position: relative combined with position: absolute.

Live Demo

Get rid of these last two lines:

div#iHeader { height:50px; background:#009900; }
div#iWrapper  { height:100%; padding-top:-50px; padding-bottom:-150px; overflow:auto; }

Replace them with:

div#list {
    position: relative
}
div#iHeader {
    height:50px; background:#009900;

    width: 100%;
    position: absolute;
    top: 0;
    left: 0
}
div#iWrapper { 
    overflow:auto;

    width: 100%;
    position: absolute;
    top: 50px;
    left: 0;
    bottom: 0
}

here's a slightly different way to do it so you don't need to use the top and bottom co-ordinates together - that way it can be made to work in IE7 too

(this does involve putting IE6/7 into Quirks mode though, but if it's any use see the comment before the Doctype how to do that)

JSBIN - IE7 compatible version

This is the quite similar to thirtydots, in that it uses a mixture of relative and absolute, but this method uses the border-box box-sizing model so space can be created by padding and still maintain the use of height: 100%;

Delete that 1k Height div, and make this iWrapper ver flow auto. So change this:

<div id="iWrapper">
  <div style="height:1000px;">
    test test
  </div>
</div>

to this:

<div id="iWrapper" style="overflow: auto;">
    test test
</div>

Or add it to your stylesheet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!