admin管理员组文章数量:1321449
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
3 Answers
Reset to default 9Using 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())
本文标签: javascriptSet DIV height so that it reaches the bottom of the viewportStack Overflow
版权声明:本文标题:javascript - Set DIV height so that it reaches the bottom of the viewport - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742099633a2420744.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论