views:

909

answers:

3

I'm using this solution, which has worked for me before:

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

I'm currently working on a site, and it's not working. I think it's because I'm using absolute position on some divs on the page. Instead of sticking to the bottom of the page, the footer shows up under the header, on top of the absolutely positioned divs. How can I get sticky footer to work in this situation?

<div id="wrap">
        <div id="container">

            <div id="myDiv">
               ...content...
               ... this div is absolutely positioned
            </div><!-- END aboutText -->

        </div><!-- END container -->
   <div class="push"></div>

</div><!-- END wrap -->
<div id="footer">
    ...footer content
</div>


Actually it's working now. Not sure why - one of those CSS mysteries. Here's a related question though - How do you set a minimum browser height, so that when someone is resizing the browser (making it smaller), the footer stops moving up and covering the content?

Edit - here's the CSS. The footer sticks to the bottom fine, but it covers the content divs on the page if the browser window is small.

html, body {
    height: 100%;
}


#wrap{
    width:950px;
    margin: 0 auto -80px;
    min-height: 100%;
    height: auto !important;
    height: 100%;

}


.push {
     height: 80px;

 }

#footer{
     height: 80px;
     background-image:url(../images/img.jpg);

}

#container{
    position:relative;
}



#someDivWithinTheContainer{
    position:absolute;
    left:230px;
    top:300px;
}
A: 

The correct answer is position fixed, except that IE6 does not support that property.

A: 

Here's what I use for sticking the footer at the bottom. With this method, the footer never overlaps the content, no matter how small the window gets. If you edit it, make sure the padding-bottom on the #body div is greater than the height of the #footer div - this is what prevents overlap. I don't have any pages with absolutely-positioned content, so I don't know how it behaves with that; for floated content, naturally you need to have a clearing block after it, otherwise the #body div shrinks down.

CSS:

html, body {margin:0;padding:0;height:100%;}
#container {min-height:100%;position:relative;}
#body {padding:10px;padding-bottom:2em;zoom:1;}
#footer {position:absolute;bottom:0;width:100%;height:1em;}

html:

<body>
  <div id="container">
    <div id="body">
      (body contents)
    </div><!-- #body -->
    <div id="footer">
      <p>(footer text)</p>
    </div><!-- #footer -->
  </div><!-- #container -->
</body>

And then to fix IE6, I add a conditional comment:

<!--[if lt IE 7]>
<style type="text/css">
#container {height:100%;}
</style>
<![endif]-->

It's also important to have a doctype declaration so IE will be in standards mode, not quirks mode.

Martha
A: 

Fixed positions an element relative to the window frame, ignoring whatever scrolling happens within the body of the page.

People will sometimes use absolute because it is similar, but different.

One of the biggest misconceptions about "absolute" is that it is absolutely positioned within a page (at least based on all the people I've interviewed recently). It's not. Absolute means the element is positioned absolutely within its closest containing "positioned" element-- any element that doesn't have "position: static" (the default). If you don't position anything else, then it's the body, as you expect. Once you start using position, you will change what the element is relative to.

I suspect this is what you have run into.

ndp