📚 Encyclopedia

Web Development · updated 2026-10-13

CSS layout gotchas on phones

cssgridflexboxresponsivemobileoverflowdark-mode

Small CSS behaviors that broke mobile layouts on Justin's sites, each with the rule that prevents it. Most show up as "the page scrolls sideways on a phone" or "the nav never collapses".

Grid children refuse to shrink

Grid and flex items default to min-width: auto, meaning "never narrower than my content". One long unbroken string (a job title with white-space: nowrap, a URL) then stretches its track and widens the whole page on a phone. Fix: size tracks with minmax(0, 1fr) instead of 1fr (plumb applied grid-template-columns: minmax(0, 1fr) to its .stack, .card and .list), or set min-width: 0 on the flex/grid child, plus overflow-wrap: anywhere where text may be long.

Inline display overrides media queries

An inline style="display: flex" has higher specificity than any stylesheet rule, so a media query that hides the element on small screens never wins. The Hunsley Hills header's desktop nav stayed visible on phones and the hamburger stayed hidden for this reason. Toggle responsive visibility only through classes. body { overflow-x: hidden } is a defensive guard, not a fix.

Fake cursors and flex

A fake block-cursor <span> placed after a flex: 1 input gets pushed to the far right edge. Use the native caret, styled with caret-color.

Height on mobile browsers

100vh includes the area under the collapsing URL bar; 100dvh is the visible height. Older browsers (Safari 15 and older, Chrome 107 and older) ignore dvh, and a lone dvh declaration leaves the element with no height. Declare both, fallback first:

.win { height: 100vh; height: 100dvh; }

Default-styled <a> elements can be unreadable on a dark theme (dark blue on near-black). Style links explicitly or render them as buttons.

Tap targets and text

44x44 px is Apple's minimum touch target, 48x48 px is Material's; 16 px minimum body text on mobile (smaller inputs also trigger iOS zoom-on-focus).

Checking for overflow

Compare document.documentElement.scrollWidth to the device width in a real mobile emulation; innerWidth is not trustworthy and headless --window-size=390 does not give a 390 px layout viewport. See Headless Chrome testing gotchas.

Browser support floor

For a personal site, a floor of Safari 15 / Chrome 95 (roughly iPhone 7 and Android 5 era) was audited in July 2026: - Fine at that floor: flex gap (Safari 14.1), aspect-ratio (Safari 15), clamp()/min()/max() (Safari 13.1), inset (Safari 14.1), Object.fromEntries (Safari 12.1), Element.animate() (Safari 13.1), padEnd (ES2017). - backdrop-filter degrades gracefully (no blur). - Needs care: dvh (fallback above), canvas ctx.roundRect() (Chrome 99 / Safari 16; add a small arcTo-based polyfill that clamps the radius and accepts an array of radii). - The audit found no optional chaining, ??, ||=, replaceAll, flatMap or .at() in the site. Most of those are fine at Safari 15, but Array.prototype.at() needs Safari 15.4, so check each newer API against the floor rather than assuming. Pre-ES6 browsers (IE11, Safari before 10) die on template literals and arrow functions; accepted as out of scope.

See also

Linked from

Sources: plumb memory (gotchas), hunsley memory (hhs-frontend), jah memory (justinahampton-site)