Menu

I Deleted My Scroll-Lock Library's Ugly Hack. `scrollbar-gutter` Replaces It.
📰

I Deleted My Scroll-Lock Library's Ugly Hack. `scrollbar-gutter` Replaces It.

DEV Community: css·Parsa J·14 days ago
#6aRL5L5F
#devtocss#devto#dev#scrollbar#gutter
Reading 0:00
15s threshold

You open a modal. For one frame, before you can even read what it says, the page behind it flinches — the whole column of text shifts a few pixels to the right, like the browser flinched too.

Close the modal and it snaps back. Nobody styled that. Nobody asked for it. And if you build UI on Windows or Linux, you've shipped it to production without noticing, because on a Mac with the default trackpad scrollbars, it's nearly invisible. That's the part that makes this bug so sticky: the person who can see it and the person who has to fix it are usually not using the same operating system.

The fix everyone reaches for first

The standard explanation is that overflow: hidden on <body> — the thing every modal, drawer, and dropdown uses to stop the page scrolling behind it — also removes the vertical scrollbar. Removing the scrollbar hands its width back to the content. The content reflows into that space.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.