This example highlights the importance of the parent container having a defined height for vertical centering (
items-center
) to work as expected.
The red parent below uses
flex items-center justify-center
, but has no explicit height. Its height is determined by its content. Notice the inner box is horizontally centered but not vertically within an imaginary larger space.
* The item is centered within the space the parent *actually occupies*, which is just the height of the item itself.
The green parent below also uses
flex items-center justify-center
, but crucially has
h-48
to give it a fixed height. Now,
items-center
works as expected for vertical centering.