views:

127

answers:

4

Hello, I'm not new at CSS, but this is problem for me and I can't solve it. I need to build layout as below:

Layout

Divs that are at the bottom and at the top have fixed heights. The one in the center have to be exacly in the height of PAGE HEIGHT - DIV 1 HEIGHT - DIV 3 HEIGHT or in some cases smaller.

Also it have to had this size setted because I predict that sometimes it's content will be bigger than it and then it will need a scrollbar inside.

I will accept case when DIV2 will be smaller, but never too big to fit to page size with DIV1 and DIV3.

Any solutions will be good, not only using CSS, but if you have an idea you can throw some Javascript too... I will be grateful for any solution.. even not fully correct :)

+8  A: 

I believe you want something like this

<div id="header" style="position:absolute; top:0px; left:0px; height:200px;overflow:hidden;"> 
</div> 
<div id="content" style="position:absolute; top:200px; bottom:200px; left:0px; overflow:auto;"> 
</div> 
<div id="footer" style="position:absolute; bottom:0px; height:200px; left:0px; overflow:hidden;"> 
</div> 
John Hartsock
Great solution, thank you Mr. John Hartsock...
ŁukaszW.pl
No problem. I use this layout all the time. Its flexible and easy to use. No javascript, just pure html and CSS. you can also use the same technique to split content into two creating a left navigation menu
John Hartsock
+2  A: 

Using jQuery to set DIV2's height on window resize:

var $div1 = $('#DIV1'),
    $div2 = $('#DIV2'),
    $div3 = $('#DIV3'),
    $window = $(window);

$window.resize(function ()
{
    $div2.height($window.height() - ($div1.height() + $div3.height()));
});

is another option I've used.

Matt Ball
Aaaa.. some js solution, nice.. thanks for help...
ŁukaszW.pl
+4  A: 

This will help you center divs vertically and horizontally

http://demo.tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/demo.html

Catfish
Very good link, thanks.. Will be helpfull...
ŁukaszW.pl
A: 

I'm not sure if i understand exactly what you ask. But what about this.

<html>
<head>
<style>
body {
    margin : 0
}

#top {
    position: absolute;
    top: 0;
    left: 0;
    height: 100px;
    border: solid 1px black
}
#middle
{
    position: absolute;
    top: 100px;
    bottom: 100px;
    left: 0;
    width: 100%;
    overflow: auto;
    border: solid 1px green;
}

#bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 100px;
    width: 100%;
    border: solid 1px blue;
}

</style>

</head>
<body>
    <div id="top"></div>
    <div id="middle"></div>
    <div id="bottom"></div>
</body>
</html>
Jonnio