|
Project Information
Members
Featured
Downloads
Links
|
Browser Compatibility Update(03/30/2010) This technique has been verified in ALL modern browsers. If you are experiencing any issues with this technique in IE8 (or any other browsers), please read this: http://code.google.com/p/cleanstickyfooter/issues/detail?id=2 Overview(project updated 08/12/2009) Over the past couple of months I have run across a few "sticky footer" techniques. While these techniques are okay, I felt that they were a little to invasive with their hacks, such as using the "clear fix" hack. About a year ago I had to conquer the "sticky footer" problem on a project I was working on. Ever since then I have been refining my technique, and feel that now it's a perfect time to release what I like to call the "cleanStickyFooter". There is only one hack, which is a height targeting hack for Internet Explorer 6 and older browsers like it. The HTMLLets start off by building out the basic HTML needed for this technique.
Looking at the HTML below, you see a div with the id of "content_inner_wrapper", the inner wrapper is only used if you have a site where you have a centered content area. In our case we do, so we add this div in. Same rules apply for the "footer_inner_wrapper" inside of "footer_wrapper".
The CSSI am going to start off by showing all of the required CSS to make this work (except the last two lines), then break it down line by line.
RequiredFirst starting off with the "html, body" selector, we are going to set not only the body but the html tag to a height of 100%, without the html tag at a height of 100% this wont work.
Next if not already done so, want to clear the default margin the browser applies.
The next block is the most crucial. In this block we are going to do the following:
The footer wrapper we will simply asign a height, the above block pushes everything down for us. We will also push this div out to a width of 100%.
The main deal with the next block is we need to set a bottom padding of 41px to counteract the -41px margin we set above. We are also setting a width of 100%.
Required in certain casesUse the next two below if you have all of your content in a centered containing div, in our case the div is 942px wide. If not, disregard the following two blocks. Use the block below when the content is scrolled horizontally, we will want to set a min-width on the footer_wrapper and the content_wrapper. The min-width should be the width of the container (see the next block below). Without this there will be a gap of empty space on the right side. Min-width will work in older versions of IE if you have a width set above, in our case we have a width of 100% set. To see what I'm talking about here, simply remove the min-width, and refresh your page. Make sure you scroll in enough where you see the horizontal scroll bar. Then scroll to the right, you will see an empty area. Now put that min-width back in there :)
Lastly we are going to set the width of our container for the content. We are also going to center the container by using the common margin: 0px auto.
BrowsersThis has been tested in Firefox (2, 3, 3.5), Internet Explorer (6, 7, 8), Safari, Opera, & Google Crome. The DifferenceGoogle "sticky footer", I have listed below why this technique works better than the top results from this search. http://ryanfait.com/sticky-footer/ - This technique is similar, but cleanStickyFooter takes it much further. The technique located here doesn't play nicely when you want to make your footer have a width of 100%. http://www.cssstickyfooter.com/ - This technique is one out of many I am referring to when I say its invasive with CSS clearing hacks. I think I will stop there, do some research yourself (if you haven't already done so) and you will see most techniques use z-indexes and clearing hacks, when they really aren't necessary. |