I want to make my <html>
and <body>
tags be the entire height of the viewport if the page isn't tall enough to warrant scrolling, or the entire height of the web page if it does.
At the moment I'm using this CSS:
html, body {
height: 100%;
}
Which works a treat if the web page isn't tall enough for the user to scroll, however on a long webpage it only goes to the height of the viewport on the users browser. I also tried:
html, body {
min-height: 100%;
}
but that just seems to have the same effect as having no height
declaration at all.
using max-height in body element will wrap the content within the viewable size of page and remove the scrolling or extra whitespace.
A starting point:
(or add a container div with an ID, etc if you have issues with some browsers.)
EDIT: Adding full code example below:
CSS:
This is the solution for Making html and body stretch to 100% height and more if the page scrolls
You will need to specify the
overflow
attribute for the particular div. It will make sure your content is shown even when page is scrolled or content is more.Have you tried:
That should set the height of the elements to the viewport and if they go beyond, it will have a scrollbar, here is an example:
http://codepen.io/r3plica/pen/jBaPYB
It sounds like your goal is for the body to
if that's the case the following snippet should help