Vertical Alignment with Box Alignment

suggest change

When the parent uses Grid, center its child in the block direction with align-items:

.parent {
  min-block-size: 20rem;
  display: grid;
  align-items: center;
}

To center on both axes, use place-items: center. When the parent uses Flexbox, use align-items: center for the cross axis and justify-content: center for the main axis.

The older position: relative; top: 50%; transform: translateY(-50%) technique remains useful in unusual positioning contexts, but it should not be the default for ordinary layout.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents