Making the footer stick to the bottom of the page when there is little content

http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

When logged in to wordpress the top bar for the editor messes the height of the page so it looks like the is an unnecessary scroll, but that is just fine when not logged in.

How to use the CSS Sticky Footer on your website

Add the following lines of CSS to your stylesheet. The negative value for the margin in .wrapper is the same number as the height of .footer and .push. The negative margin should always equal to the full height of the footer (including any padding or borders you may add).

  1. * {
  2. margin: 0;
  3. }
  4. html, body {
  5. height: 100%;
  6. }
  7. .wrapper {
  8. min-height: 100%;
  9. height: auto !important;
  10. height: 100%;
  11. margin: 0 auto -4em;
  12. }
  13. .footer, .push {
  14. height: 4em;
  15. }

Follow this HTML structure. No content can be outside of the .wrapper and .footer div tags unless it is absolutely positioned with CSS. There should also be no content inside the .push div as it is a hidden element that “pushes” down the footer so it doesn’t overlap anything.

  1. <html>
  2.     <head>
  3.         <link rel=”stylesheet” href=”layout.css” … />
  4.     </head>
  5.     <body>
  6.         <div class=”wrapper”>
  7.             <p>Your website content here.</p>
  8.             <div class=”push”></div>
  9.         </div>
  10.         <div class=”footer”>
  11.             <p>Copyright (c) 2008</p>
  12.         </div>
  13.     </body>
  14. </html>

Multicolumn layout with Sticky Footer

Add clear to the .push div

  1. .footer, .push {
  2. clear: both;
  3. }

Adding margins to elements is messing up the footer.

Simply use padding instead, and all your worries will go away.

I put this on my site and it doesn’t work right in browser X. You have something wrong with your code!

Check to see if the example CSS Sticky Footer page works in that browser. If it does, then you have something wrong with yours!

Leave a Reply

Your email address will not be published. Required fields are marked *