-2

I tumbled upon this question here

I am not clear of how html and body elements behave.

Look at the answer, He put the height of the body and html to 100% which helped him solve his answer,

How did that happen? please help me.

Community
  • 1
  • 1
buoyantair
  • 347
  • 4
  • 11

1 Answers1

0

One problem is that html and body have height:auto by default, which is rather hard to do calculations with. I mean, what is 50% of auto? So, those calculations fail.

And even if you can know the height the body, that is, look at the resulting height after it has been rendered, it's still not the same as the height of the screen. Example:

html {background:lime}
body {background:black; color:white}
This is the body

See? body is only one line high. So any child of body that you set to height:100% will still be as high as its parent.

Therefore the solution is to set both html and body to height:100%, which will give them the same height as the window.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150