brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: scrollbar-gutter: stable stops css layout shift when a scrollbar appears

Css
~/tips/tip-css-scrollbar-gutter-stable-shift

.sidebar-list { overflow-y: auto; scrollbar-gutter: stable both-edges; }

Reserves space for the scrollbar so the layout does not shift when scrolling becomes possible.

Content that jumps sideways when a page gets long enough to scroll looks sloppy.

html { scrollbar-gutter: stable; }
.sidebar-list { overflow-y: auto; scrollbar-gutter: stable both-edges; }

On systems with classic scrollbars, the bar takes space from the page only when there is overflow, so a page that grows past the window height shifts the layout by about 15 pixels. scrollbar-gutter: stable always reserves that strip. both-edges adds the same space on the other side to keep the content centred. Overlay scrollbars take no space, so there you will see no difference. Phones use them, and so does macOS when a trackpad is the main input.

Further reading: MDN: scrollbar-gutter

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link