I am trying to create a head area that is 100px in height and spans 100% in width. I need 2 columns with the left one being 250px wide and 100% in height down to the footer. The right column should be 100% of the remaining page width and 100% in height to the footer. The footer should be at the bottom of the page and 100px in height and 100% in width. Even if there is no content in the 2 columns, I need them to stretch down to the footer and have the footer visible without scrolling down to it.
Here is what I have so far.
<div id="top"><p>Lorem ipsum dolor sit amet</p></div>
<div id="left"><p>Lorem ipsum dolor sit amet</p></div>
<div id="right"><p>Lorem ipsum dolor sit amet</p></div>
<div id="bot"><p>Lorem ipsum dolor sit amet</p></div>
body, html {
height: 100%;
}
body {
margin: 0px;
}
p {
margin: 0px;
}
#top {
height: 100px;
background-color: #F4F4F4;
}
#left {
width: 250px;
height: 100%;
background-color: #878787;
float: left;
margin-bottom: -100px;
}
#right {
background-color: #323232;
height: 100%;
margin-bottom: -100px;
}
#bot {
clear: right;
height: 100px;
background-color: #DCDCDC;
margin-top: -100px;
z-index: 100;
position: relative;
}
Here is another example with a table
<table height="100%" width="100%" cellspacing="0" cellpadding="0" border="0" class="" id="">
<tr>
<td colspan="2" style="background-color: powderblue; height: 100px;">Header</td>
</tr>
<tr>
<td style="background-color: gray; width: 350px;">Left Col</td>
<td style="background-color: DarkSeaGreen">Right Col</td>
</tr>
<tr>
<td colspan="2" style="background-color: tomato; height: 100px;">Footer</td>
</tr>
</table>
In those cases, I recommend
position: fixed
orabsolute
. It works just likecalc()
, but in old browser too!Demo
It would also be a good idea (in case browser window is too small), to also use
Demo
Use
calc()
. It's awesome.DEMO *FullscreenDEMO*
Ok, here is an alternative using css tables. It works like this:
#top
and#bot
are always100px
tall.#left
will be250px
wide if it can.#right
occupies all horizontal space left by#left
#left
and#right
push#bot
down.#left
and#right
will grow so that#bot
will be at the bottom of the window.Demo
It requires changing your html to
Instead of
100000px
, use a value greater than the height of#left
and#right
.Since it's a bit hacky, you may prefer a css-tabular-only approach without floats, but doesn't work on IE8, although it only uses CSS2.1 features.