Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari: VH units applied to parent element doesn't allow 100% height in child?

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?

like image 893
Neil Avatar asked Jun 03 '14 14:06

Neil


People also ask

Is VH relative to parent?

Relative units works based on parent element length. Relative units applied element adjusts lengths based on its parent element length.

What height 100vh mean?

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.

How is VH calculated?

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.

What does VH mean in Javascript?

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.


2 Answers

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/

like image 161
Stephan Muller Avatar answered Nov 09 '22 06:11

Stephan Muller


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%;
}   
like image 35
pstenstrm Avatar answered Nov 09 '22 06:11

pstenstrm