Making HTML content expand to fill the window

爱⌒轻易说出口 提交于 2019-12-04 03:00:49

Using the height: 100% CSS attribute should make it work.

See if Dave Woods 100% Height Layout Using CSS works for you.

It's a little known aspect of the position: absolute; CSS property that will give you the layout you are looking for. You can absolutely position an element in ALL 4 directions, top, right, bottom and left. This means a box can be as fluid as the browser and always remain the same distance away from the edges of it's container that you specify.

div {
    position: absolute;
}
#main {
    top: 8em; // 8em
    left: 0; 
    bottom: 8em; // 8em
    right: 300px;
    overflow: auto;
}
#header {
    top: 0;
    left: 0;
    right: 0;
    height: 8em;
}
#sidebar {
    top: 8em;
    right: 0;
    bottom: 8em;
    width: 300px;
    overflow: auto;
}
#footer {
    bottom: 0;
    left: 0;
    right: 0;
    height: 8em;
}

For an example check out http://www.sanchothefat.com/dev/layouts/cssframes.html and then view source and pull apart the CSS to see how it's done in a more complex example.

If you take this approach you have to absolutely position ALL the main container <div>s. Use ems if font-size is a concern.

PS. There is a gotcha in that IE6 messes up (shock!) however the example I have provided has an IE6 fallback. Just a fixed height will be fine though.

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