footerStickAlt revisited

Posted on Sat Mar 11 07:06:00 UTC 2006

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.

Posted in html/css, Quid Pro Quo  |  Tags  |  12 comments

Comments

  1. Arron Tow Arron Tow said // May 20, 2006 at 07:03 AM

    The only problem with this is that it doesn't work with xhtml. Add these lines to the top and you will see: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>

  2. Pascal Pascal said // May 20, 2006 at 07:25 AM

    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. Arron Tow Arron Tow said // May 20, 2006 at 10:02 AM

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

  4. Pascal Pascal said // May 20, 2006 at 12:41 PM

    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 html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> doctype. Arron, are you having problems with this site with Opera and Netscape?

  5. Arron Tow Arron Tow said // May 21, 2006 at 02:40 AM

    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 Tow Arron Tow said // May 22, 2006 at 12:08 AM

    Have you been able to reproduce this behavior?

  7. Pascal Pascal said // May 22, 2006 at 01:05 AM

    Sorry Arron, not yet. I'll try it today.

  8. Pascal Pascal said // May 22, 2006 at 04:59 PM

    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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> or <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 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.

  9. Doog Doog said // Feb 09, 2007 at 03:49 AM

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

  10. Doog Doog said // Feb 09, 2007 at 03:50 AM

    *when broswer resizes

  11. Pascal Pascal said // Feb 09, 2007 at 04:02 AM

    Do you have problem with this page? It uses this technique and seems to work fine here. Or does this page http://blog.nanorails.com/footerstickalt-revisited.html work? These work for me with version 2.0.4 of safari. One of the key is to have that "main-bottom-space" section. Do you have a link with a page that displays the problem?

  12. Doog Doog said // Feb 09, 2007 at 04:58 AM

    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.

(leave url/email »)

Comment Markup Help