Our landing page hero had a classic desktop bug: a large gradient headline ("...on Telegram and your website") was wrapping to one line thanks to white-space: nowrap and sliding underneath a floating phone mockup positioned absolutely on the right. At 1280px the word "website" visually collided with the phone frame, and a caption chip under the phone was clipped off the left edge.

The fix took ten minutes once we stopped reaching for z-index. This is the write-up, because the actual root cause was an old media query, not the new layout.

The setup (simplified)

<section class="hero"> <div class="hero-copy"> <h1>Automate customer chats on <span class="grad">Telegram and your website</span></h1> </div> <div class="hero-visual"> <div class="phone">...</div> <div class="fc fc3">EN interface language</div> </div> </section> 
.hero h1 .grad { white-space: nowrap; /* keeps the gradient phrase on one line */ background: linear-gradient(...); -webkit-background-clip: text; color: transparent; } /* the offender: a card-offset rule written for an older, wider layout */ @media (min-width: 861px) { .hero-visual .fc3 { inset-inline-start: -22%; } } 

white-space: nowrap means the <h1> box grows as wide as the text wants, regardless of its column. The absolutely-positioned phone sits on top in paint order. At 861-1280px the one-line gradient phrase was wider than the text column, so it rendered under the phone frame. It only "worked" before because the phrase used to wrap.

Why z-index is the wrong fix

Putting the text above the phone "solves" the overlap by making it a collision instead: gradient text painted over a device bezel looks broken in a different way. The correct invariant is geometric: the text box must end at least N px before the phone frame starts. We picked 40px.

The fix

Three small changes, one commit:

/* 1. let the phrase wrap again */ .hero h1 .grad { white-space: normal; } /* 2. cap the heading so the wrapped lines stay short */ .hero h1 { font-size: clamp(40px, 5vw, 64px); } /* 3. reposition the floating chip so it clears the text column */ .hero-visual .fc3 { top: 26%; inset-inline-start: -9%; } /* 4. give the chip its own spot on tablets */ @media (max-width: 1080px) { .hero-visual .fc3 { inset-inline-start: 4%; } } /* 5. the old rule only applies above the new breakpoint */ @media (min-width: 1081px) { .hero-visual .fc3 { inset-inline-start: -22%; } } 

The load-bearing change is #5. The @media (min-width: 861px) rule predated the current two-column hero and was yanking the chip left on viewports the layout no longer supported. Scoping it to min-width: 1081px (just above our tablet breakpoint) kept the wide-screen offset and stopped it from fighting the mid-range layout.

How to measure the overlap instead of eyeballing it

Headless Chrome plus a tiny script beats squinting at screenshots. Grab the bounding boxes:

// run in devtools, or via chrome --headless --dump-dom with an injected script const h1 = document.querySelector('.hero h1').getBoundingClientRect(); const phone = document.querySelector('.hero .phone').getBoundingClientRect(); const gap = phone.left - h1.right; console.log({ textRight: h1.right, phoneLeft: phone.left, gap }); 

We want gap >= 40 at every desktop width. Then loop the widths:

for w in 900 1080 1280 1440 1920; do google-chrome --headless --disable-gpu \ --screenshot=hero-$w.png --window-size=$w,900 \ https://localhost:8000/ 2>/dev/null done 

No Playwright needed for a layout check. google-chrome --headless --screenshot on a locally served copy of the site is enough, and it's fast enough to run per commit.

What we verified

  • 900px (tablet): chip moved inside the viewport, no clipping.
  • 1280px: gap ≈ 165-175px. Text stops well before the phone.
  • 1440px and 1920px: same invariant holds; the wide-screen chip offset (rule #5) only kicks in above 1080px where there's room.
  • Mobile (390px): untouched, single column, no absolute positioning involved.

Takeaways

  1. white-space: nowrap on a heading is a layout time bomb. It makes the element's width a function of its text, not its container.
  2. When an element overlaps on some desktop widths, grep your old min-width media queries before touching the layout. Ours was written two designs ago.
  3. Define the invariant as a number (text ends ≥40px before the frame) and measure it with getBoundingClientRect. "Looks fine on my screen" is not a test.
  4. Headless Chrome screenshots at 900/1280/1440 are cheap enough to be part of every CSS fix.

The site this ran on is chatora.us.ci (disclosure: I work on it). The hero there now holds the 40px invariant from 900px up.