简体   繁体   中英

How do I know if my content takes up the whole page vertically?

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 (ie 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

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

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
}

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.

没有看到你的HTML就很难回答,但如果你使用的是jquery,只需使用outerHeight来获取页面上元素的垂直大小,并将其与window.height进行比较。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM