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>
Try This
Working Fiddle
Here is a simple CSS-grid solution (I used
50px
instead of100px
so we can see it in the reduced snippet)And here is with flexbox:
http://codepen.io/anon/pen/jhCed
Bonus: stretched left column background of 100%.
You could use the Sticky Footer Concept: Sticky Footer
The Result would look like this: Working Fiddle
But stretching the columns without content to the bottom is not possible without javascript. Why would you want to do that anyways?
You could use
flex
Here's a working example:
http://jsfiddle.net/6Mp4g/2/
Flex is a newer CSS3 workaround to creating stretched and responsive-like layouts for content. It can get a bit complicated, so I'll just link to the source and some syntax how-to:
https://developer.mozilla.org/en-US/docs/Web/CSS/flex
HTML:
CSS:
This is my solution using grid. You need to have two nested grids to always show bottom grid item, even when content overflows.
This uses backward compatible
-ms
-code