I have a very simple situation, where I want to set a container element to 80vh
and then have the inner div to be 100% of that height. On Chrome this will render correctly, however on Safari, the inner element doesn't have 100% of the 80vh
height.
.container {
background-color: red;
width: 100%;
height: 80vh;
}
.inner {
height: 100%;
background-color: blue;
}
Here is a fiddle showing this issue: http://jsfiddle.net/neilff/24hZQ/
On Chrome the element is blue, in Safari it is red. Is there a work around for this issue without applying 80vh
to the height of the .inner
div?
Relative units works based on parent element length. Relative units applied element adjusts lengths based on its parent element length.
Here, 100vh means that the initial body height will take 100% of the viewport height, whereas the use of min-height instead of height will let the body element grow even more if necessary.
Viewport Height (vh). This unit is based on the height of the viewport. A value of 1vh is equal to 1% of the viewport height.
Viewport Height (vh): It is based on the viewport's height, for example, a value of 1vh is equal to 1% of the viewport height.
This is a known bug with vh
and vw
in Safari. You can fix it by setting height: inherit
on the inner element:
.inner {
height: inherit;
}
http://jsfiddle.net/24hZQ/47/
You'll need to set position: absolute;
to the .inner
element.
.container {
background-color: red;
width: 100%;
height: 80vh;
position: relative;
}
.inner {
height: 100%;
background-color: blue;
position: absolute;
width: 100%;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With