While justify-content
allows us to change the placement and spacing of the items along the main axis, we also need to align items along the cross axis.
The main axis is defined by the flex-direction property (either horizontal for row or vertical for column), while the cross axis runs perpendicular to the main axis. This is where the align-items property comes into play.
For example, with column
direction, the items stretch to the
full width of the container.
Stretching is the default behaviour
and
this can be changed
using the align-items
property:
This is what each of the values does:
flex-start
Items are aligned at the beginning of the container.
flex-end
Items are aligned at the end of the container.
center
Items are aligned in the center.
baseline
Items are aligned such that the bottom of all elements are in a line.
stretch
Items are stretched full width in case of the column
direction, and full height in case of the row
direction.
Here's what this property does
when the flex direction
is set to column
:
Try changing the direction to
column-reverse
and see what happens.