Spot the bug - #131: Centered Showcase Card

Why is my mystery treat card staying completely off center?

.treat-stage {
  display: flex;
  width: 100vw;
  height: 100vh;
  align-items: center;
  text-align: center;
  background: #2b1055;
}

.mystery-card {
  width: 220px;
  padding: 24px;
  border-radius: 16px;
  background: #ff5e7e;
  color: #ffffff;
}

Reply with what is broken and how you would fix it.

The text-align: center; on .treat-stage is for inline content, not for centering flex items.

You need to add justify-content: center; to the flex container to horizontally center the card.

Spot the Bug answer: The ‘text-align: center;’ property is incorrectly applied to the flex container instead of the flex item.

The fix:
Remove ‘text-align: center;’ from ‘.treat-stage’ and add ‘justify-content: center;’ to ‘.treat-stage’.

Why:
The ‘text-align’ property only centers inline content, not block-level flex items. To horizontally center flex items within a flex container, ‘justify-content: center;’ should be used on the flex container.

First-answer leaderboard

  1. @kirupa - 6 (firsts) :trophy:
  2. @Apexcodes - 5 (firsts)
  3. @adnanahmed - 2 (firsts)
  4. @emmawalter5 - 2 (firsts)