3 ms·
Strongly related: viewport units (vw, vh, vmin, vmax) are fundamentally and irreconcilably broken if your document has scrollbars, because they include the size
by chrismorgan 6y ago
Strongly related: viewport units (vw, vh, vmin, vmax) are fundamentally and irreconcilably broken if your document has scrollbars, because they include the size of document scrollbars, so that 100vw is equal to 100% + 17px if you have a 17px wide scrollbar there (the most likely value on Windows), so now all of a sudden you have a horizontal scrollbar too. Or your nicely calculated layout that thought that 33vw + 33vw + 33vw < 100% is now wrong and wrapping the third block on screens less than 1700px wide. There used to be a weird way of opting out of scrollbar inclusion (I think it involved `overflow: scroll` and something else on the root element, I think, but I don’t remember the exact incantation), but Firefox was the only browser that implemented it, and no one else wanted to (they said “no one wants this”—untrue, I say—“and it’s weird and inconsistent”—which was true).
We need a new set of units that excludes document scrollbars. Or a constant like env(scrollbar-width) that represents the scrollbar width so that you can subtract it yourself, which would be useful in a few other places as well (instead I’ve done the likes of `var(--scrollbar-width, 20px)` and calculate and define --scrollbar-width on the root element in JavaScript).
- RonanTheGrey 6y agoI dealt with this just a few days ago. A client's design was mocked in webflow and it decided to use 'static' for the header at 100vw. Which meant that on browsers that hide the scroll bar, the page jiggles left and right every time you scroll. That was fun to fix because I had to rebuild the entire header since a ton of other webflow-generated CSS depended on that thing being static.