I've been away from marking up sites for some time. So, now we have HTML5 and a lot of new features in CSS. I have a common site layout with fixed size header and footer. And of course main content area in between. By default page should take 100% of window height (i.e. content area expands). And if content is long page vertical scrollbar appears and all like usual. Usually I used to do it by something like this:
<body>
<table id="main" ...>
<tr>
<td id="header-and-content">
<div id="header">contains logo, nav and has fixed height</div>
<div id="content">actual content</div>
</td>
</tr>
<tr>
<td id="footer">
fixed size footer
</td>
</tr>
</table>
</body>
And accompanying css:
html, body { height:100% }
table#main { height:100% }
td#footer { height:123px }
So, it's obsolete. You, who keeps abreast of new markup techniques, how it is done by now in 2011?
UPD People, issue not about semantic markup or using divs. I know what it does mean. Issue now in - how do I tell footer to stay at bottom even while content is empty or short. When content is long enough footer just go down as it would do in other case. Absolute and fixed is not the solution (at least at its basic form)
SOME SUMMARY UPDATE
- I've tried method with usage of display:table and display:table-row and it works: little content, more content
- Method Make the Footer Stick to the Bottom of a Page was adviced by Andrej. It works also: little content, more content
Some disappointment though I feel: first method is just those tables but without table
tag. The second is really old, I've avoided to use it because it resembles hack. My god, nothing new :)
Well, first of all in 2011 we dont use tables for layout anymore!
If I were you, I would write the markup like so:
And the CSS would be the same except the changed selectors
For a fixed footer, I would suggest to use
position:absolute
or maybeposition:fixed
- it depends how you want it to behave (scroll with page or always stay at bottom).To make a "sticky" footer, that will be at the bottom of the page but move with the content, this method will do the trick.
In 2013 there is still nothing that beats a decent table that has respectively thead/tfoot/tbody.
The below (valid HTML5 page) is a fixed header and footer, 100% height and NOT ANY resize trouble.
Today, you would do like this (not much different really)
http://jsfiddle.net/5YHX7/3/
and
Let me add my contribution by adding 3 columns to your header / main / footer layout:
http://jsfiddle.net/ESrG9/
As you asked for "modern"... anno 2016 I have maybe a better answer than in 2013:
use the 100vh solution in CSS3. vh is a new unit and stands for ViewPort height.
But if you wish to be compatible with old browsers, use the code in my 2013 answer.
Technically you could probably still get away with laying out your page with table tags but it is now considered bad practice. It is considered good practice to use "semantic" web markup which means using tags for their intended purposes so a table tag should be used to represent table data and not invisible design. DIVs are intended for use designing your invisible page layout. A list apart is a great website resource for understanding these concepts.
This article is good for understanding semantic markup: http://www.alistapart.com/articles/12lessonsCSSandstandards
So all that said, here is a sample page that does what you want:
http://peterned.home.xs4all.nl/examples/csslayout1.html