fix: stabilize scrollbar gutter to stop layout shifting between pages#209
Merged
Conversation
On-behalf-of: @SAP mirza.kopic@sap.com Signed-off-by: Mirza Kopić <mirza.kopic@gmail.com>
|
aaronschweig
approved these changes
May 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the content and navbar shifting horizontally ("jumping") by a few millimetres when navigating between documentation pages.
Root causes
Two distinct causes, both surfacing on browsers that reserve scrollbar space (e.g. macOS "Show scroll bars: Always", common on external/ultra-wide monitors):
Page-to-page shift (all pages). The whole page scrolls on
<html>and the layout is centered within--vp-layout-max-width. Pages whose content overflows show a vertical scrollbar; pages that fit don't. That ~15px width change re-centers everything, so the logo, nav and content column shift between a scrolling and a non-scrolling page (e.g./reference/vs/concepts/).Home ↔ menu-page shift (version selector / right-hand nav). VitePress positions sidebar-page navbars and content with
100vw-based padding (gutter-inclusive), while the home navbar centers via100%(gutter-aware). With the gutter reserved, the two differ by half a scrollbar width, so the version selector and right nav items jump when moving between the home page and any menu page.Fix
All in
.vitepress/theme/custom.css:html { scrollbar-gutter: stable }— reserve the gutter on every page so it never toggles.@media (min-width: 1440px)block recomputing the sidebar-page navbar/content paddings with100%instead of100vw, so internal pages are gutter-aware and line up with the home page.max()floors the values so narrow viewports fall back to VitePress defaults.No-op on overlay-scrollbar systems (which never had the jump).
Verification
Measured with headless Chrome against the dev server:
🤖 Generated with Claude Code