Files
30-seconds-of-code/snippets/flexbox-centering.md
2023-04-28 22:27:48 +03:00

593 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Flexbox centering snippet
layout
basket-paper 2020-12-30T15:37:37+02:00

Horizontally and vertically centers a child element within a parent element using flexbox.

  • Use display: flex to create a flexbox layout.
  • Use justify-content: center to center the child horizontally.
  • Use align-items: center to center the child vertically.
<div class="flexbox-centering">
  <div>Centered content.</div>
</div>
.flexbox-centering {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
}