0

In CSS, to set the height of a div so that it stretches from the top of the page to the bottom is done like so:

html, body, #xdiv {
    height: 100%;
    min-height: 100%;
}

The problem is, this executes straight away, so when the text or content loads, it's not 100% any more. My question is, can I use Jquery or JS to set the above after page load?

4
  • what have you tried? if you know jquery it should be fairly straight forward. Commented Jun 25, 2015 at 17:02
  • You mean like with $(window).load(function() {? Commented Jun 25, 2015 at 17:03
  • Your question doesn't make sense, you didn't explain what xdiv is, but if they were one within the other they would always fill 100% of the screen. Setting it later on would make no difference. Commented Jun 25, 2015 at 17:06
  • xdiv is a div.. And no, it doesn't do it automatically since I've had to manually set it with CSS. And it worked fine until I started to add content. Commented Jun 25, 2015 at 17:08

2 Answers 2

1

You can use load:

$(window).load(function() {
   $('html, body, #xdiv').css({ "height": "100%", "min-height": "100%"});
});
Sign up to request clarification or add additional context in comments.

1 Comment

I think you messed up with the brackets, but let me see if it works.
0

Try This: http://jsfiddle.net/00ho9kgv/

To vertically-center content, you'll need to wrap and use display: table, etc: http://jsfiddle.net/00ho9kgv/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.