I haven't tested this css, but I think it'll do what you want:
html {
width: 100%;
height: 100%;
}
body {
position: relative;
width: 100%;
height: 100%;
}
#footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
The width/height properties ensure that the body is always at least the height of the viewport. You can then absolutely position the footer inside it to get it at the bottom. If the body's content goes over, the body will grow, and the footer will stay at the bottom of the body.
Now, there is a drawback: the footer may overlap the last bit of body content. To work around this, you could add this CSS to the body:
body {
-moz-box-sizing: border-box;
box-sizing: border-box;
padding-bottom: 40px;
}
Substitute 40px
for whatever the size of your footer is. By setting padding-bottom
we reserve that space for the footer. The box-sizing
properties ensure that this 40px
(or whatever the right number is) gets reserved from that body height itself, and not added on at the bottom. Basically, it keeps vertical scrollbars from appearing when the page wouldn't naturally need to scroll.