最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set DIV height so that it reaches the bottom of the viewport - Stack Overflow

programmeradmin8浏览0评论

How to set the height of this DIV so that it reaches the bottom of the viewport ? The DIV cannot be absolutely positioned ; it's in the flow.

<html>
   <body>
      Hello world...
      <div>xxx</div>
   </body>
</html>

If there is a CSS solution (which I doubt), it's great but using JS/jQuery is fine. CSS3 is fine too.

How to set the height of this DIV so that it reaches the bottom of the viewport ? The DIV cannot be absolutely positioned ; it's in the flow.

<html>
   <body>
      Hello world...
      <div>xxx</div>
   </body>
</html>

If there is a CSS solution (which I doubt), it's great but using JS/jQuery is fine. CSS3 is fine too.

Share Improve this question asked Mar 12, 2012 at 15:46 BlacksadBlacksad 15.4k16 gold badges74 silver badges81 bronze badges 2
  • 2 possible duplicate of How to apply 100% height to div? – bfavaretto Commented Mar 12, 2012 at 15:47
  • could you tell us why you need it? maybe there's another way to achieve the same goal without inserting lots of javascript in your app and making the code harder to maintain, not to mention the annoying browser patibility issues... – Castilho Commented Mar 12, 2012 at 15:51
Add a ment  | 

3 Answers 3

Reset to default 9

Using jQuery:

var h = $(window).height() - $('div').offset().top;
$('div').height(h);
  • DEMO

Start with:

body, html { height:100% }

Then give your DIV height:100%

Use $(window).height() to get the actual height of the element

$("div").height($(window).height())
发布评论

评论列表(0)

  1. 暂无评论