Easy CSS fixed footer
I’ve seen a lot of tutorials out there for how to have a fixed footer using CSS. Most of them require all kinds of nested div’s, wrappers, and so on. It’s really very simple, and this code can be copied and pasted into almost any website template without modifying the entire set up. See below.
CSS file:
.footer_spacer{
height:60px;} /* This height should be equal to or greater than the
footer. his ensures content is not cut off by your footer */
#footer{
position:fixed; /* keeps it from moving at all */
bottom:0; /* keeps it at the bottom of the screen */
width:100%; /* stretches to fill the width of the body tag */
height:30px; /* sets the height. should be equal to or less than the
footer_spacer height */
}
HTML: <div class = "footer_spacer"></div> <!--Nothing goes in here. This is just a spacer. --> <div id = "footer"> Enter Footer Content Here </div> <!--This is the actual footer. Use CSS to style to your needs -->
And that is it. The footer_spacer div creates a “buffer” below the rest of your page for the footer to rest in, thus eliminating any content from being cut off. If your webpage uses floats, read on. If not, then you should be able to copy and paste this into your exisiting web page with no problems. Tested in IE7, FF2, FF3 and Safari. Should work in IE6 as well.
If you use floats, as some of my pages do, you only have to make one small modification. The footer_spacer div may need to be increased to accomodate the position of your floats. Also, be sure to add a <div style = “clear:both;”></div> before the footer_spacer div to make sure it is positioned correctly. Any issues getting this up and running, feel free to e-mail me at dcostalis@gmail.com.
Stumble it!
Post Info
This entry was posted on Sunday, December 9th, 2007 and is filed under css, development. It has 1,287 viewsComments Feed. | Leave Comment | Leave Trackback.
Previous Post: Wordpress isn’t perfect, and so is my grammer »
Next Post: Windows Vista Service Pack 1 RC1 »

























March 19th, 2008 11:32
Hi,
thanks for the above code, this is really unbelievable that this issue with fixed footer/header can be achieved so easyly with only a few lines of CSS.
Unfortunately it doesn’t work in IE6. Could you please tell me how to get this up and running in this *** browser as well?
thanks a lot
Robert
March 27th, 2008 23:26
Robert -
Thanks for the comment! One thing I’ve noticed is that IE6 will only let it work if you specify the DOCTYPE. (more on that at http://www.w3.org/QA/2002/04/valid-dtd-list.html).
In short, add this line to the VERY top of your page:
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
and it should work just fine in IE6. Thanks again!
April 28th, 2008 00:21
myspace div layout…
Regards,…
May 16th, 2008 03:49
The transitional doctype means IE is in quirks mode and this will introduce all sorts of other layout problems. If you care about how it looks in IE, this technique is not enough. (Yes, it should be just this simple, but in reality, it’s not.)
May 16th, 2008 18:30
Andrew-
True. However, I haven’t noticed any way to make IE6 behave the way that it should… whether or not you specify transitional or strict, there will still be issues that need to be dealt with when attempting any sort of advanced layout.