tags:

views:

354

answers:

2

I have a site I'm trying to build and I've hit one little snag thats driving me insane. Essentially on pages without enough content to fill the viewport, I want to have the last div (my footer, fill the rest of the viewport, but it's currently being cut off.

My html looks like this:

<body>
  <div id="header"> </div>
  <div id="subNav"> </div>
  <div id="content"> </div>
  <div id="footer"> </div>
</body>

I tried using html, body, footer { height:100%; } but that creates much more space then needed, essentially a full screen length of blank content in the footer.

How do I get my footer just to fill teh rest of the screen without adding a scroll bar?

Thanks in advance, One Frustrated Coder.

+2  A: 

I'm pretty sure the only way to do this is by calculating the absolute remainder hight.

I.E, with jQuery

$('#footer').height( ($(window).height() - $('#header').height() - $('#subNav').height() - $('#content').height()) + "px" );

You would want to do this on window resize to allow for a dynamically resizing window.

$(window).resize(function(){...});
Stefan Kendall
Yep, can't be done well without javascript.
runrunraygun
A: 

If you don't want to go the jQuery route, the poor man's version of this is giving #content a min-height that will make it work in most displays, and/or by giving your footer plenty of padding on the bottom. It might trigger a scrollbar in some instances, as you're just controlling how short the page can be, though.

(Or you can just accept it as a limitation of the medium. Stack Overflow, for example, just has its footer float above whitespace if the page is too short.)

D_N