I have a simple 2-column layout with a footer that clears both the right and left div in my markup. My problem is that I can't get the footer to stay at the bottom of the page in all browsers. It works if the content pushes the footer down, but that's not always the case.
Update:
It's not working properly in Firefox. I'm seeing a strip of background color below the footer when there's not enough content on the page to push the footer all the way down to the bottom of the browser window. Unfortunately, this is the default state of the page.
The flex solutions worked for me as far as making the footer sticky, but unfortunately changing the body to use flex layout made some of our page layouts change, and not for the better. What finally worked for me was:
I got this from ctf0's response at https://css-tricks.com/couple-takes-sticky-footer/
None of these pure css solutions work properly with dynamically resizing content (at least on firefox and Safari) e.g., if you have a background set on the container div, the page and then resize (adding a few rows) table inside the div, the table can stick out of the bottom of the styled area, i.e., you can have half the table in white on black theme and half the table complete white because both the font-color and background color is white. It's basically unfixable with themeroller pages.
Nested div multi-column layout is an ugly hack and the 100% min-height body/container div for sticking footer is an uglier hack.
The only none-script solution that works on all the browsers I've tried: a much simpler/shorter table with thead (for header)/tfoot (for footer)/tbody (td's for any number of columns) and 100% height. But this have perceived semantic and SEO disadvantages (tfoot must appear before tbody. ARIA roles may help decent search engines though).
Use absolute positioning and z-index to create a sticky footer div at any resolution using the following steps:
position: absolute; bottom: 0;
and the desired heightdiv
that wraps the body content withposition: relative; min-height: 100%;
div
that is equal to the height plus padding of the footerz-index
of the footer greater than the containerdiv
if the footer is clippedHere is an example:
For me the nicest way of displaying it (the footer) is sticking to the bottom but not covering content all the time:
CSS :
HTML:
This should do the trick if you are looking for a responsive footer aligned at the bottom of the page,which always keeps a top-margin of 80% of the viewport height.
jQuery CROSS BROWSER CUSTOM PLUGIN - $.footerBottom()
Or use jQuery like I do, and set your footer height to
auto
or tofix
, whatever you like, it will work anyway. this plugin uses jQuery selectors so to make it work, you will have to include the jQuery library to your file.Here is how you run the plugin. Import jQuery, copy the code of this custom jQuery plugin and import it after importing jQuery! It is very simple and basic, but important.
When you do it, all you have to do is run this code:
there is no need to place it inside the document ready event. It will run well as it is. It will recalculate the position of your footer when the page is loaded and when the window get resized.
Here is the code of the plugin which you do not have to understand. Just know how to implement it. It does the job for you. However, if you like to know how it works, just look through the code. I left comments for you.