News for hackers. Stuff that matters.
Re:Avoid 100vh on Mobile Web by chrenn on Monday September 30, 2019 @05:57AM (#21113340)
I recently had to deal with this issue, you'd think this had to be solved by now.

So as suggested on SO: https://stackoverflow.com/a/55003985,

    min-height: -webkit-fill-available;
works exactly as intended in Safari (mobile and desktop), but unfortunately breaks in desktop Chrome for me, so I ended up putting it in a media query for mobile only.
Re:Avoid 100vh on Mobile Web by uallo on Monday September 30, 2019 @03:36AM (#21112625)
Here is an article from 2015 about the same problem but with more context and examples:

https://nicolas-hoizey.com/2015/02/viewport-height-is-taller...

Re:Avoid 100vh on Mobile Web by eloff on Saturday September 28, 2019 @08:37PM (#21104135)
The reason they do it is to avoid the redraw when hiding/showing the address bar. If you use JavaScript you get that performance issue. Having been bit by this issue, I think chrome and Safari made the wrong decision. We worked around it with JavaScript, which I'm sure performs worse and was a pain to implement.
Re:Avoid 100vh on Mobile Web by greggman2 on Monday September 30, 2019 @05:28AM (#21113199)
they made the right decision imo. vh units can be used for font-size. if you set font-size: 5vh; (5% of height) then as they shrank the browser chrome/address bar the size of the entire page and all word wrapping etc would change. that would be bad user experience. that's just one example of the unintended consequences of the mobile UI dynamically changing size under normal use.
Re:Avoid 100vh on Mobile Web by hyfgfh on Monday September 30, 2019 @03:37AM (#21112630)
Yep, having to add an event listener for that is really an awful idea.

I had a similar problem with mobile Chrome, you can add a media queue for that. But we have a specification for a reason, if we started to add work around for every minor inconsistency...

Re:Avoid 100vh on Mobile Web by abdusco on Monday September 30, 2019 @04:01AM (#21112746)
An easy solution is to add a height transition:

    .full-height {
        min-height: 100vh;
        transition: height 1000s steps(1);
    }
This will let you maintain the initial height with the address bar excluded, and won't let it change when the bar disappears. Steps timing function is to avoid costly layout calculations.
Re:Avoid 100vh on Mobile Web by jannes on Monday September 30, 2019 @04:10AM (#21112781)
Wouldn't this change after 16m 40s?
Re:Avoid 100vh on Mobile Web by wereHamster on Monday September 30, 2019 @05:32AM (#21113220)
Yes, that is true.

Increase to hours, days, or years as you feel appropriate for your audience. Unless the visitors spend days looking at the screen, they won't notice.

Re:Avoid 100vh on Mobile Web by pritambarhate on Monday September 30, 2019 @08:10AM (#21114390)
This kind of exemplifies the problem with web development in general. 100vh would have been so intuitive if it worked correctly. This is why a lot of web devs hate CSS. One needs to remember so many hacks to get the webapps behave correctly! It's one of the reasons bloated frameworks like bootstrap become popular and all users pay the price.
Re:Avoid 100vh on Mobile Web by tsar_nikolai on Monday September 30, 2019 @04:52AM (#21113003)
You can fall back to the oldskool way of setting the height of the parent nodes to 100%:

  html, body, .full-height {
    height:100%
  }
I guess this is exactly the thing the viewport units were designed to overcome, but at least it's a pure css solution.
Re:Avoid 100vh on Mobile Web by macando on Monday September 30, 2019 @05:07AM (#21113093)
If you have a site that's N screens high and you want to set the height of a div (i.e. an image) so it covers the whole landing area (what the user sees when the site loads) then this code won't help. You have to use vh
Re:Avoid 100vh on Mobile Web by dao- on Monday September 30, 2019 @05:15AM (#21113132)
Or you use position:fixed?
Re:Avoid 100vh on Mobile Web by macando on Monday September 30, 2019 @05:19AM (#21113146)
And set the height to what? Using percentages means 100% relative to the parent. What if the whole site is the parent and that site is 3 screens high? I haven't found the way to make it work without relying on vh or JavaScript.
Re:Avoid 100vh on Mobile Web by jaxn on Monday September 30, 2019 @06:30AM (#21113501)
Set top: 0; bottom: 0
Re:Avoid 100vh on Mobile Web by macando on Monday September 30, 2019 @07:34AM (#21114069)
Maybe we are talking about 2 different things. I want to stretch the image to the bottom of the visible area not to the bottom of the site. If the height of the parent is 100% and that parent is the site itself and it's 5000px high (because the rest of the content made it that high) then setting the bottom to 0px will stretch the image's height to 5000px.
Re:Avoid 100vh on Mobile Web by goblin89 on Monday September 30, 2019 @07:46AM (#21114179)
> you want to set the height of a div (i.e. an image) so it covers the whole landing area (what the user sees when the site loads)

I believe “what the user sees when the site loads” is often referred to as “above-the-fold”. “Landing area” may be interpreted to mean the whole landing page. Perhaps repliers were confused by the phrasing.

Re:Avoid 100vh on Mobile Web by macando on Monday September 30, 2019 @08:05AM (#21114346)
Bingo! Above the fold is the more common term. I usually call it "landing area" and the whole thing I call "landing page". Naming is important :)
Re:Avoid 100vh on Mobile Web by Zekio on Saturday September 28, 2019 @07:53PM (#21103922)
Does this apply to all browsers on mobile?

Because I've never experienced this in Firefox on android

Re:Avoid 100vh on Mobile Web by uallo on Monday September 30, 2019 @03:29AM (#21112586)
Firefox handles it differently than Chrome. In Firefox, the amount reflecting 100vh is changed while the address bar is hidden. So you always see the full 100vh, but the layout might change if for example the spacing is calculated based on the vh unit (or vmax in portrait mode, or vmin in landscape mode).
Re:Avoid 100vh on Mobile Web by masklinn on Monday September 30, 2019 @04:54AM (#21113018)
> the layout might change if for example the spacing is calculated based on the vh unit (or vmax in portrait mode, or vmin in landscape mode).

That sounds like a good thing, and pretty much the entire point of using viewport-relative units?

I'd certainly expect vh/vw-based layouts to change when I change the size of my viewport, whether by hiding and showing ancillary UI elements (e.g. sidebars or control bars of my browsers) or by manipulating the browser window directly.

Re:Avoid 100vh on Mobile Web by uallo on Monday September 30, 2019 @05:00AM (#21113053)
Most of the time, yes. But the layout might jump just because you scroll up/down a little. For example, the spacings might get slightly larger when you scroll down and slightly smaller when you scroll up.
Re:Avoid 100vh on Mobile Web by brlewis on Monday September 30, 2019 @08:08AM (#21114367)
Subtle changes during scrolling seem way preferable to me than hiding content that, according to standards, should be shown.
Re:Avoid 100vh on Mobile Web by chanind on Saturday September 28, 2019 @08:03PM (#21103974)
Firefox on Android works properly iirc, but sadly most users don't use it.
Re:Avoid 100vh on Mobile Web by GoToRO on Monday September 30, 2019 @04:27AM (#21112860)
My proposal is to not fix anything and let people see that the other browsers are worse.
Re:Avoid 100vh on Mobile Web by missblit on Monday September 30, 2019 @07:17AM (#21113903)
Per [1] it sounds like it should be usable with "position: fixed". Though I can't test it right now.

There's some interesting (hopefully not outdated) discussion in the Chromium bug here [2][3] which helps explain why things the way they are (balancing several competing constraints).

[1] https://developers.google.com/web/updates/2016/12/url-bar-re... [2] https://bugs.chromium.org/p/chromium/issues/detail?id=428132 [3] https://github.com/bokand/URLBarSizing

Re:Avoid 100vh on Mobile Web by jariz on Monday September 30, 2019 @08:02AM (#21114321)
Using JS over CSS for sizing elements rarely is a 'better solution', mostly because of flashes of unstyled content - especially on mobile where it might take longer for the JS to fully initialise.

Like other comments on here say, just use height: 100% instead.

Re:Avoid 100vh on Mobile Web by macando on Monday September 30, 2019 @04:34AM (#21112894)
And no way to test it with the address bar visible in the Chrome emulator. So it's all nice and dandy until you actually load the site on a mobile device.
Re:Avoid 100vh on Mobile Web by jjcm on Monday September 30, 2019 @05:27AM (#21113191)
Mobile html dev feels like it’s taken a step back lately. With vh not being the true viewport height and with user-scalable no longer being respected, it’s become very difficult to build advanced apps for the mobile web. A lot of it feels like reactionary changes due to abuse by devs of these features which lead to bad UX, but it comes at the expense of allowing richer apps.
Re:Avoid 100vh on Mobile Web by sidyapa on Monday September 30, 2019 @05:35AM (#21113241)
There's a better solution for 100vh on mobile by csstricks - https://css-tricks.com/the-trick-to-viewport-units-on-mobile...
Re:Avoid 100vh on Mobile Web by chrismorgan on Monday September 30, 2019 @04:53AM (#21113007)
I recommend just avoiding viewport units altogether; this isn’t the only problem with them. The fact that they include scrollbars on the document element means that 100vw and 100vh are just never what you desire, if scrolling can occur.
Re:Avoid 100vh on Mobile Web by masklinn on Monday September 30, 2019 @04:59AM (#21113041)
> The fact that they include scrollbars on the document element

What do you mean by that? Do you mean that the surface taken by scrollbars is not removed from the viewport?

That would make sense on mobile devices as scrollbars are generally transient overlays, or when e.g. OSX is set up in that configuration (there's a system setting so native scrollbars can be either a transient overlay or a reserved area).

Re:Avoid 100vh on Mobile Web by azangru on Monday September 30, 2019 @06:24AM (#21113463)
> the surface taken by scrollbars is not removed from the viewport?

Yes.

Which means that if your element's width is 100vw and the page height is larger than the viewport height so that it shows a vertical scrollbar, then suddenly you get a horizontal scrollbar as well.

People who build sites on Macs make this mistake all the time, because on MacOS browsers hide their scrollbars by default, and developers do not immediately see the consequences of this CSS rule. When you view these pages on Linux or Windows machines (or if you tell MacOS not to hide scrollbars), then you see the annoying horizontal scrollbar.

Re:Avoid 100vh on Mobile Web by masklinn on Monday September 30, 2019 @06:39AM (#21113553)
> Which means that if your element's width is 100vw and the page height is larger than the viewport height so that it shows a vertical scrollbar, then suddenly you get a horizontal scrollbar as well.

Oh wow that's insane.

edit: apparently the "useful" behaviour used to be opted-in using overflow: scroll, but only firefox implemented that, they asked if it was really useful (when nobody else cared) and… it was dropped from the spec.

Re:Avoid 100vh on Mobile Web by greggman2 on Monday September 30, 2019 @05:20AM (#21113153)
use the correct feature for your use case. for a dynamic background behind a scrolling page use 100vh if the size depends on the height otherwise the background will do this strange shrink and grow thing as the UI changes size
Re:Avoid 100vh on Mobile Web by sheerun on Monday September 30, 2019 @05:09AM (#21113102)
This issue has been reported at least 4 years ago to Webkit: https://bugs.webkit.org/show_bug.cgi?id=141832
Re:Avoid 100vh on Mobile Web by benbristow on Monday September 30, 2019 @04:36AM (#21112907)
I've always used 100vh (or just over) to ensure my footer is always at the bottom of the page. I assume this is fine still?
Re:Avoid 100vh on Mobile Web by markdown on Monday September 30, 2019 @04:45AM (#21112963)
Use the flexbox solution instead: https://news.ycombinator.com/item?id=21110985
Re:Avoid 100vh on Mobile Web by benbristow on Monday September 30, 2019 @05:13AM (#21113115)
Still uses min-height: 100vh;
Re:Avoid 100vh on Mobile Web by greggman2 on Monday September 30, 2019 @05:35AM (#21113237)
I believe on mobile safari and chomre your footer will be off the bottom until the user scrolls down and the browser us shrinks
Re:Avoid 100vh on Mobile Web by dessant on Monday September 30, 2019 @04:37AM (#21112912)
As one of the comments below the post mentions, `html, body {height: 100%}` should work just fine.
Re:Avoid 100vh on Mobile Web by cyptus on Monday September 30, 2019 @05:20AM (#21113150)
stackoverflow discussion and more Infos on this: https://stackoverflow.com/q/37112218/1216595
Re:Avoid 100vh on Mobile Web by LoSboccacc on Monday September 30, 2019 @05:07AM (#21113094)
I just wish browsers would follow standards instead of having half dozen frail workarounds that have to be reworked at each drop of new browser versions