2

I have a site that I've been working on the the past couple of weeks. I have a very nice footer on it, problem is, it doesn't stay at the bottom. I've come up with a simple solution.

If the page isn't completely filled (i.e. the content only goes half way down), absolute position the footer to the bottom.

If the page is overflowing (vertically), leave the footer as just another element.

Problem is, I don't know how to check if my content is overfilled. Is there a way to check if the document fills up all the space vertically? The only thing I can think of is to check to see if the vertical scroll-bar is enabled, however, I don't know how to check for that either.

I'm using jQuery, answers with it are fine. Thanks!

EDIT

OK, my question was apparently misunderstood. Sorry guys, I don't need solutions on how to keep my footer at the bottom. I need ways of determining if data overflows on the y-axis. I happened to mention my reason why I needed to know this. Don't make me regret this guys :p

Freesnöw
  • 30,619
  • 30
  • 89
  • 138

5 Answers5

3

I've used this successfully many times over: http://cssstickyfooter.com. No JavaScript needed at all.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Problem is, my footer will be a variable height depending on some different things. I'd rather just have it dynamically done. – Freesnöw Oct 04 '11 at 21:42
2

Using jQuery, $(window).height() is how you get the height of the viewport. You can check this value against your content's height:

if($("#content").height() > $(window).height()) {
    // absolute position my footer
}
rekamoyka
  • 1,122
  • 11
  • 15
1

Use the Sticky Footer technique like Matt posted.

The basic idea of it is that you set a static height for your footer. Make your webpage take up the full height of the browser. Push the footer off the screen from the #content div, and then move the footer back onto the page with a negative margin value.

Chris G.
  • 3,963
  • 2
  • 21
  • 40
1

It's hard to answer without seeing your HTML, but if you are using jquery just use outerHeight to get the vertical size of the elements on your page and compare it to window.height

Porco
  • 4,163
  • 3
  • 22
  • 25
1

You could apply the css clearfix trick. As stated it is hard with out seeing your code. Even still this could work.

Example:

<html>
  <style>
    .clearfix:after {
      content: ".";
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
     }
  </style>

<body>

  <div id="content" class="clearfix">
  </div>

  <div id="footer">
  </div>

</body>
</html>

This helps to keep content from overflowing and should keep your footer at the bottom or below your content.

Nicole
  • 217
  • 2
  • 7