0

Recently I've been learning more about flexbox, and I just stumbled across some unexpected behavior.

I have a div, with a header element inside of it:

<div>
    <h2> Hello </h2>
</div>

The div has

{
  display: flex;
  justify-content: center;
  align-content: center;
  flex-direction: column;
}

I'm trying to center my header horizontally (in the cross-axis), and my understanding is that align-content: center would do that.

However, it only works if I apply align-self: center to the header.

Any idea what might be causing this behavior? I thought align-content on the flex item was equivalent to align-self on each of the children. Why is it only working if I specify align-self?

Nathan
  • 73,987
  • 14
  • 40
  • 69

2 Answers2

1

No need to apply the property to the header , Just include align-items: center; instead of align-content:center to the CSS and it will work perfectly.

Basit Mir
  • 97
  • 5
0

Flex examples

official documentation

Try

flex-direction: row;

Or

display: flex;
align-items: center;
justify-content: center
Vladislav
  • 476
  • 2
  • 13