March 12, 2012

Set DIV height so that it reaches the bottom of the viewport

Question by Blacksad

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.

Answer by paislee

Using jQuery:

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

Answer by Starx

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

$("div").height($(window).height())

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!