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.

Tags:

12 Responses to “footerStickAlt revisited”

  1. Arron Tow March 11, 2006 at 3:06 pm #

    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">

  2. Pascal March 11, 2006 at 3:06 pm #

    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 March 11, 2006 at 3:06 pm #

    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 March 11, 2006 at 3:06 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 March 11, 2006 at 3:06 pm #

    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 March 11, 2006 at 3:06 pm #

    Have you been able to reproduce this behavior?

  7. Pascal March 11, 2006 at 3:06 pm #

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

  8. Pascal March 11, 2006 at 3:06 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 March 11, 2006 at 3:06 pm #

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

  10. Doog March 11, 2006 at 3:06 pm #

    *when broswer resizes

  11. Pascal March 11, 2006 at 3:06 pm #

    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 March 11, 2006 at 3:06 pm #

    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.

1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208| buy cheap tenormin buy karela online purchase online without prescription nolvadex proscar uk where to buy no prescription needed secure online purchase risperdal no prescription cheapest accutane pills no prescription antibiotics online purchase indocin generic tablets buy herbal somaeurax and cost buy without a prescription nitroglycerinAccutane Online Doxycycline online Buy Cheap Lexapro Online No Prescription Prednisone Online payday loans online no checking account