in html/css, Quid Pro Quo

footerStickAlt revisited

Here’s the html used here

<html>
<body>
  <div id="wrapper">
    <div id="blog-header">
    </div>
    <div id="main-wrapper">
      <div id="sidebar">
      </div>
      <div id="main-content">
      </div>
    </div>
    <div id="main-bottom-space">&nbsp</div>
  </div>
  <div id="footer">
  </div>
</body>
</html>

and the css used here:

body {
/* force footer to stick at bottom */
height: 100%;
}

/* avoid trampling on the footer by reserving some space (IE) */
#main-bottom-space {
height: 26px;
clear: both;
}

#wrapper {
position: relative;
/* force footer to stick at bottom */
height: 100%;
}

#main-wrapper {
position: relative;
}

#main-content {
float: left;
}

#sidebar {
float: right;
}

#footer {
clear: both;
/* stick at bottom */
height: 26px;
position: relative;
margin-top: -26px;
}

The key difference is to add the #main-bottom-space <div> element.

12 Comments

  1. The only problem with this is that it doesn’t work with xhtml.

    Add these lines to the top and you will see:

  2. Do you mean that to make this xhtml compliant, you need to add the proper DOCTYPE line?
    I believe this should work in most versions of xhtml 1.0, transitional, and even 1.1.
    Just realized that there is a semi-colon missing in the & nbsp ; entity in the example above (unless Markdown is playing funny with it.

  3. Yes, adding the DOCTYPE and the xmlns to the html tag make it not work in Orpera or Netscape. IE seems fine though.

  4. hmmm, I tried it with Firefox and IE, and I think I had tried it with Opera (I think it was 8). I’ll try that again and see if I can figure out something. If anyone has a solution, don’t hesitate to pitch in!
    I’m using it here with a doctype. Arron, are you having problems with this site with Opera and Netscape?

  5. Actually, I made a small test page using your code and tested it with Netscape, IE, and Opera. All 3 browsers worked fine until I added the doctype.

  6. Arron, it appears that the missing bit it to have
    html {
    height: 100%;
    margin-bottom: 1px;
    }

    The margin-bottom: 1px is not critical for this, but is from [Force the rigth scroll bar to appear](http://blog.nanorails.com/articles/2006/03/11/forcing-the-right-scrollbar-to-appear-on-your-web-page)

    Adding this works wit Netscape 8.1, Opera 8.5, Firefor 1.5 and IE 6.

    I’ve added a page with a [working example](http://blog.nanorails.com/footerstickalt-revisited.html)

    It works with either
    or

    Lesson learned: extracting an example from a full page does not necessarily work till you’ve tried it in all cases. Created a working snippet will serve you well in the long run.

  7. I’m having problems with this in Safari. The footer tramples the content when broswer. Please help.

  8. Thanks for the quick reply. I’m using Safari v1.3 here. I’ll try and test my page on a newer version of Safari. Finally, I’ll try and provide a link as soon as I can.

Comments are closed.

  • Related Content by Tag