Exploring Element Height and Viewer Height
https://www.w3schools.com/cssref/pr_dim_height.asp
The CSS property for height determines the vertical size of an element.
https://www.w3schools.com/cssref/pr_dim_length.asp
This value is equivalent to 1% of the height of the browser window's initial containing block.
https://www.w3schools.com/cssref/pr_dim_min-height.asp
When using min-height, you are setting the lowest possible height that an element can have. It ensures that the height does not become smaller than the specified min-height value.
We encountered a complex mix of different height values while working on this project.
The initial style looked like this:
#main-content {
background-image: ...
height: 120vh
}
With this setup, the element was instructed to be 120% of the browser window's height. Although this approach may have worked well in most cases, it could lead to overflow issues when the content inside the container exceeded its boundaries. This would cause parts of the content to extend past the wrapper and appear outside. Since the background color was applied to the wrapper, any overflow would cover the default background (white).
To address this, we made the following adjustment:
#main-content {
background-image: ...
height: 100%;
min-height: 100vh;
}
This modification served two purposes. Firstly, by setting the wrapper's height to 100%, it ensured that the wrapper encompassed all the contained elements without any overflow. However, what if the viewer's height surpassed that of the content? In such cases, white space could still be visible at the bottom. To account for this scenario, we included the min-height
property which guarantees that the wrapper's height will be at least 100vh. Therefore, if the content is shorter than the viewer, the wrapper will expand to occupy the entire viewing area.