CSS issue with "vh" unit of measure on mobile devices

21 views
Skip to first unread message

Charlie Veniot

unread,
Dec 11, 2022, 1:46:10 PM12/11/22
to TiddlyWiki
Using "100 vh" for height of things in a web page is problematic on mobile devices, because mobile web browser menus (when they appear) take up display space (either at the top or the bottom) and push the "100 vh" part of a web page out of view.

Charlie Veniot

unread,
Dec 11, 2022, 1:48:29 PM12/11/22
to TiddlyWiki
BTW, this is not an issue (that I know of) with anything TiddlyWiki.

This is just a CSS "heads-up" if you use CSS' "vh" unit of measure in anything you do that might be used in a mobile web browser..

Télumire

unread,
Dec 11, 2022, 2:58:28 PM12/11/22
to TiddlyWiki
This is an issue for tiddlywiki themes/custom UI that place a searchbar at the top or bottom of the screen.

Currently the best solution is to use javascript : https://dev.to/nirazanbasnet/dont-use-100vh-for-mobile-responsive-3o97
Second best is to use min-height: -webkit-fill-available; (if calc isn't needed)
And finally, the upcoming dynamic viewport units should fix this issue: https://caniuse.com/viewport-unit-variants

There is also env() that may be usefull for this kind of things but I'm not sure how that works exactly https://developer.mozilla.org/en-US/docs/Web/CSS/env#examples

Charlie Veniot

unread,
Dec 11, 2022, 3:07:09 PM12/11/22
to TiddlyWiki
Well, I don't know what makes the found solution I adopted not as good as the other ones.  If you know of any flaw in it, please advise.

I'll keep your other references in mind if I run into problems.  Thanks!

Télumire

unread,
Dec 11, 2022, 3:45:46 PM12/11/22
to TiddlyWiki
Well in your particular use case it works sure, but as pointed out on the stack overflow article you linked to, writing

height: calc(100vh - calc(100vh - 100%))

Is the same as writing

height: 100%

Because it translates to 100vh - 100vh + 100%. In order to be able to use height: 100%, you must propagate that height from the root element through all the children till the target element. Sometimes it may be too difficult. A more general/reliable solution
is the javascript approach I mentioned in my post.
Reply all
Reply to author
Forward
0 new messages