DEV Community

Cover image for Mobile issue with 100vh | height: 100% !== 100vh [3 solutions]

Mobile issue with 100vh | height: 100% !== 100vh [3 solutions]

Piyush Kumar Baliyan on February 14, 2020

So there are various ways to size any element on a webpage. We are familiar with common CSS units px, em, pt (and uncommon one cm, mm, in) with sup...
Collapse
 
jochenthomas profile image
jochenthomas

Is there any solution on the market?
Esp. on IOS14/Safari we have still the same issue (as already mentioned by Leonardo).

I also tried this:
width: -moz-available; /* WebKit-based browsers will ignore this. /
width: -webkit-fill-available; /
Mozilla-based browsers will ignore this. */
width: fill-available;
But I cannot get it working.

Any advice to have a real height when the address bar gets away (I urgently need to have a "holy grail" design = fixed header + fixed footer and flexible content-area in the middle)?
Thanks for any direction...

Collapse
 
sdoigmm profile image
Steve Doig

This works for me in Chrome on desktop (i.e. it adds the --vh variable to the style of html), but it doesn't add the --vh variable to the style of html in Chrome on a Google Pixel 5. Is this because the --vh variable is only added when the viewport is resized?

(window.addEventListener('resize'...)

Collapse
 
piyushkmr profile image
Piyush Kumar Baliyan AdmitKard

I also added a initial window loaded event, in addition to resize.

Collapse
 
sdoigmm profile image
Steve Doig

I had to add a separate event listener for window's load event to performing the same function to get it to work on mobile.

Collapse
 
torstendittmann profile image
Torsten Dittmann • Edited

It is even worse, when you try to adjust to an activated mobile keyboard with 100vh :D

Collapse
 
piyushkmr profile image
Piyush Kumar Baliyan AdmitKard

Yeah, seems like mobile browsers are unable to do an implementation of the viewport with simplicity. And 100% height is another nightmare in itself. 🤯

Collapse
 
cavalcanteleo profile image
Leonardo

None of those worked on iOS 14

Collapse
 
piyushkmr profile image
Piyush Kumar Baliyan AdmitKard

Will have to check on that.