Jump to content
Nic727

HTML/Body height - 100% or auto?

Recommended Posts

Hi,

 

What is the best use of height for the HTML and body tag?

I currently use auto to don't have problem, but for my design, I need a background image to be height 100%. Should I use background height 100vh or 100% and have body/html height at 100%?

 

Thank you

Share this post


Link to post
Share on other sites

If you set height of body, html  to 100vh they will not extend beyond current viewport height of devices orientation, whatever the content and will show content beyond this background image when scrolled

If you set height of body, html to 100% they will extend to and beyond current viewport height only when content exceeds beyond that height of devices orientation and scroll along with extended background image.

Now depending what you want! You could use background-attachment: fixed; with height: 100vh to prevent background image scrolling up with content to show content extending beyond this html, body height background image.

Share this post


Link to post
Share on other sites

If you're trying to apply background images to html and body that fill up the entire browser window, neither. Use this instead:

html{ height : 100%;} body{min-height : 100%;}

the reason why you have to specify height and min-height to html and body respectively is because neither element has any intrinsic height. Both are height: auto by default. It is the viewport that has 100% height, so height: 100% is taken from the viewport, then applied to body as a minimum to allow for scrolling of content.

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...