Issues using vh units in CSS
See original GitHub issueIssue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:14 (4 by maintainers)
Top Results From Across the Web
You Shouldn't Rely on CSS 100vh and Here's Why! | Medium
Fix 100vh Issue on Mobile Devices Using CSS Only. Sometimes, the purpose of using vh unit is to simply create sections equal to...
Read more >CSS vw and vh Units: Are They Worth Using Yet? - Convoy
CSS vw and vh Units: Are They Worth Using Yet? An Introduction. Amongst the newer responsive CSS selectors, my favorites are definitely vw...
Read more >CSS fix for 100vh in mobile WebKit
A surprisingly common response when asking people about things they'd fix about anything in CSS, is to improve the handling of viewport units....
Read more >Responsive Web Design - Portfolio - Problem with vh units
Hello, I'm almost done with the personal portfolio challenge. However, the test unit doesn't accept my solution, even though I think it's ...
Read more >What are the disadvantages of vh and vw units? - Stack Overflow
The disadvantage is the same as the advantage: it is relative to the screen dimensions. This is something you probably don't want for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s how I get around this issue:
CSS variables to the rescue
Step 1: Set all
vh
values with a CSS variableExample usage:
Step 2: Hard-code a
px
-based--viewport-height
for your testsUpdate the top line of
overrideCSS.js
to something like this:The values above should match the dimensions of your
viewports
inbackstop.json
. In that example, the viewports were:The above also assumes you’re using
onReady.js
with the defaultoverrideCSS
reference intact.For Chromy folks, you’d need to adapt
overrideCSS.js
from the Puppeteer folder.Side benefit for 100vh mobile UI patterns
This idea occurred to me when I was trying to fix another problem:
As you may know, there’s a long-running “feature-not-a-bug” on iPhone (and now Android too) where
100vh
ignores the top and bottom browser bars. Those bars jump around as you scroll (and is also directionally-dependent, to my memory). The result is this:(Graphic: CSS Tricks)
More example code of the fix here.
Side note: While most people seem to be calculating
1vh
then multiplying withcalc()
, I’ve found it’s usually cleaner to set100vh
and divide, at least for the sorts of problems I’m usually trying to solve.This doesn’t seem like a Backstop problem
Given we’re seeing this
vh
behavior with Chrome’s full page screenshot feature in DevTools (as a commenter above pointed out), perhaps this should be addressed in Chromium (or whatever’s responsible for this feature)? I’d be surprised if this wasn’t a deliberate choice–even off the top of my head I can think of some advantages to handling it the way they currently are–but maybe this could be a candidate for a flag.See my bug #820 - this seems to be an issue with the way Chrome(y) takes the screenshot by resizing the page - you can reproduce the issue in desktop Chrome by using “Capture Full size screenshot” in the “Developer Tools + mobile view”. What I think we need to do is screenshot, scroll, screenshot, scroll and then stitch together.
I’ve no idea of any current + working workaround, but without a work around unfortunately I can’t use backstep 😦 😦 😦