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