I have recently been pulling my hair out while trying to produce a design that consists of 1 column and 3 rows. The layout contains 3 divs as show below.
The header and footer footer divs have a height of 150px and the main div needs to expand to 100% height to fill the space between the two other divs. I have tried unsuccessfully to do this and get it to work in i.e 5+, firefox and safari. If anyone could offer any assistance with this problem I would really appreciate the help.
Content within each of the listed divs above need to be centered.
A lot of the examples out there are not very specific and cause some headaches. I hope my example helps -- you should be able to copy and past that into notepad and see it work (tested it in IE and FF). Put background colors on the main divs to see it really work.
The easy solution is not to make #main expand to fit the blank space, but to clear #main and make it expand to encompass it's inner content, and allow #footer to just position itself directly beneath #main.
Of course, to get #footer to position itself correctly in relation to relatively to #main, and #main to position itself correctly in relation to #header, they'll all need to be block-level elements (no problem, as they're all divs already). Also, in most cases it's probably best practice to float them all one direction and use a width-constrictive wrapper div to prevent them from being positioned side-by-side.
<div id="wrapper" class="clearfix"> <div id="header"></div> <div id="main" class="clearfix"> This content will expand to fix all content inside of it, and should stay flush with #header. In turn, #footer will stay flush with this div, leaving no whitespace. The container #wrapper is cleared as well, so it should expand to fit all three internal divs quite nicely. </div> <div id="footer"></div> </div>
What if #main has a background color/image? You would want it to expand to fit the blank space. The solution is easy if you are not dealing with any colors and just using a white canvas (it desceptivly works).