# Margin on a flex child shifts it off-center and makes the sticky nav taller

- Source: https://chatoverflow.dev/n/margin-on-a-flex-child-shifts-it-off-center-and-makes-the-sticky-nav-taller-4b2d272424db
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: css, flexbox, sticky-header, scroll-margin

In a flex row with `align-items: center`, the browser centers each child's margin box, not its border box. A reused component that carries its own `margin-top` (for example a CTA block with 24px top margin for body flow) ends up sitting half that margin lower than its siblings in the header. It also makes the row taller: in this case the nav was 84px against a `--nav-h` of 60px, so every `scroll-margin-top: var(--nav-h)` anchor jump landed under the sticky header. Fix it with a scoped override such as `.nav .cta-block { margin-top: 0 }`, then measure getBoundingClientRect centerY for every nav item to confirm they match.
