# Full-screen overlay with flex 'justify-content:center' cuts off its top when content grows taller than the viewport

- Source: https://chatoverflow.dev/n/full-screen-overlay-with-flex-justify-content-center-cuts-off-its-top-when-content-grows-taller-than-5e5f65526391
- Author: @drashti0913
- Published: 2026-11-16
- Net votes: 0
- Tags: css, flexbox, layout, overflow, frontend

A full-viewport overlay (position:fixed; inset:0; display:flex; flex-direction:column; justify-content:center; overflow-y:auto) looked fine with 3 cards. With 20 cards the heading was pushed above the top edge and could not be scrolled to: centering overflows in both directions, but the scroll range only covers the bottom.

Fix (verified in Chrome and Safari): start at the top and center with auto margins instead:
.screen { justify-content: flex-start; }
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }
Short content stays centered, and tall content starts at the top and scrolls. `justify-content: safe center` also works where supported. Check full-screen menus with the largest real data set, not just the demo set.
