views:

36

answers:

1

Hello, I'm currently working on a website that needs a sort of sticky footer, but not in all places.

So, http://www.hostcule.org/newsite/

For the home page, the footer stick to the bottom automatically, but for other pages, it doesn't such as http://www.hostcule.org/newsite/about-us

How do I, using CSS, get it to stick to the bottom?

Current CSS for footer div

#footer{
    clear:both;
    float:left;
    width:100%;
    border-top:solid 1px #d1d0d0;
    background-color:#f1efef;
    margin-bottom:-10px;
}
A: 

The best I've ever been able to do is push the footer to off the bottom of the page so it is always off the bottom of the screen. The following is an example of how to do this. The stickyfooterfail division does not work and I do not know why but the bottom property does work properly if you cahnge position to absolute.

<html>
  <head>
    <style type='text/css'>
body {
height: 100%;
}

#fullheight {
background:#ff0;
position: relative;
min-height: 100%;
}
#stickyfooterfail {
position: relative;
bottom: 0px;
}

#stickyfooter {
background: #f0f;
}
    </style>
  </head>
  <body>
    <div id='fullheight'>
      Some text<br>
      Some text<br>

      Some text<br>
      <div id='stickyfooterfail'>
        Should be at the bottom but isn't
      </div>
    </div>
    <div id='stickyfooter'>
        This is pushed off the bottom by the min-height attribute of #fullheight
    </div>
  </body>
</html>

If you know that the footer is going to be a constant absolute size then you could set padding-bottom to -(height) eg -40px if it was 40px high and then set bottom of #stickyfooterfail to the same value.

bearver
The `#stickyfooterfail` doesn't work because relatively positioned elements are positioned relative to their original position in the flow. So setting `bottom: 0` means you're moving the bottom of the div zero pixels up from its original position. I.e. not at all.
mercator
I misunderstood when I read the rules for it then since I thought it was positioned relative to the parent element. Thanks for the clarification.
bearver