Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

100vh height when address bar is shown - Chrome Mobile

I came across this problem a few times and was wondering if there was a solution to this problem. My problem occurs on the Chrome mobile app. There, you can scroll down a bit and the address bar disappears. So far, so good, let's make an example:
The container's height is set to 100vh.

How it looks with the address bar

As you can see, the bottom part gets cut off.

When I scroll down, it looks like this:

enter image description here

Now it looks good. So obviously Chrome calculates the address bar's height into the viewport height. So my question is:

Is there a way, that it looks the same with or without the address bar? So that the container expands or something?

like image 426
Tobias Glaus Avatar asked Oct 17 '18 06:10

Tobias Glaus


People also ask

Does 100vh work on mobile?

Yes, 100vh is 100% of a viewport height (your device), when pure 100% only fill all available parent area (parent block can have e.g. 50px height and it will fill only to this parent height).

How do I change my height to 100vh?

The state-of-the-art way Sure! Applying min-height: 100vh to the body element should do the trick. 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.

What is min height 100vh?

Min height 100vh means the element should occupy the web browser viewport height. This is always 100 percent of the web browser's viewport height. If there is more content, the element will stretch more than the viewport's height, which is a code example that will clear things up.

How do you find the height of a viewport?

You can use the window. innerHeight property to get the viewport height, and the window. innerWidth to get its width. let viewportHeight = window.


Video Answer


2 Answers

As per this official article on Chrome web, the proper way to set the height to fill the visible viewport is with height: 100%, either on the <html> element or on a position: fixed element. As the document describes, this ensures compatibility with mobile Safari and is independent of how large the URL bar is.

like image 135
Ross Light Avatar answered Oct 03 '22 19:10

Ross Light


Try using min-height: -webkit-fill-available. You can also add it below height: 100vh as a fallback.

like image 22
cnotethegr8 Avatar answered Oct 03 '22 18:10

cnotethegr8