HTML/CSSQuestion 08 of 14
Centring an element
Answer out loud or in your head first, then compare.
Answer
The simplest way to centre an element on both axes is Grid or Flexbox.
CSS
.container {
display: grid;
place-items: center;
min-height: 240px;
}Alternative: display: flex; justify-content: center; align-items: center.
To be precise: the container needs free space on the axis where you want to see the centring. For a block with a set width, margin-inline: auto centres it horizontally.
Pitfall: text-align: center aligns inline content; it isn't a general way to centre any block vertically.
How did it go? Be honest — “Not yet” puts the question on your review list.