Skip to content

Commit 7328f50

Browse files
seanghayclaude
andcommitted
docs: fix mobile horizontal scroll via contain:layout
The real culprit was Chrome mobile's layout-viewport auto-expansion. Even when wide content (the comparison table, long code lines) sat inside an overflow-x:auto wrapper, mobile browsers still measured the descendant's intrinsic width when sizing the layout viewport — which expanded from device-width to ~2× device-width and dragged the fixed nav header along with it. Applying `contain: layout` to every overflow-x:auto wrapper inside <main> isolates the wrapper's intrinsic width from the layout-viewport calculation while keeping the inner horizontal scroll intact. Verified via Playwright at 375×800 with isMobile:true: - before: window.innerWidth = 776, html.scrollWidth = 776 - after: window.innerWidth = 375, html.scrollWidth = 375 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bf0100b commit 7328f50

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

docs/app/app.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
html {
2222
scrollbar-gutter: stable;
23+
/* Disable mobile auto-text-inflation. Without this, Chrome mobile (and
24+
mobile-emulation in DevTools) scales font sizes up in columns it deems
25+
"too narrow," pushing content wider than the viewport even when desktop
26+
narrow-width rendering is fine at the same pixel width. */
27+
-webkit-text-size-adjust: 100%;
28+
text-size-adjust: 100%;
2329
}
2430

2531
/* Stop the document itself from scrolling horizontally. Inner elements with
@@ -52,6 +58,28 @@ main > * {
5258
overflow-x: hidden;
5359
}
5460

61+
/* Cascade min-width:0 to every descendant. Flex/grid children default to
62+
`min-width: auto`, refusing to shrink below their content's intrinsic
63+
min-width — that's what lets a long unbreakable line in a deep grid cell
64+
blow out the whole page on mobile. Setting this universally is safe
65+
because elements with explicit `width` still keep their width. */
66+
main * {
67+
min-width: 0;
68+
}
69+
70+
/* The real mobile-overflow culprit. Even with overflow-x:auto wrappers,
71+
Chrome mobile (and DevTools mobile emulation) still measures intrinsic
72+
content width when computing the layout viewport — a wide table or
73+
long code line inside an overflow:auto wrapper can expand the layout
74+
viewport from device-width to ~2× device-width, which then makes the
75+
fixed nav header span the larger viewport and produce horizontal
76+
scroll. `contain: layout` isolates the wrapper's layout from the
77+
parent's layout-viewport calculation while leaving overflow:auto
78+
scrolling intact. */
79+
main .overflow-x-auto {
80+
contain: layout;
81+
}
82+
5583
body {
5684
font-family: var(--font-sans);
5785
}

0 commit comments

Comments
 (0)