CSS: align-items (flex cross axis)
align-items
- CSS property
align-itemsis for Flexbox container. - It is for aligning flexbox items along the cross axis.
align-items: stretch-
default
123123456 align-items: baseline-
like first-baseline.
123 some
thing align-items: first baseline-
- first baseline aligns the items according to the baseline of the first line of text inside them.
- Itβs useful when you have flex items with different font sizes or multiple lines of text, and you want them to line up neatly based on their text baseline.
- first-baseline β Aligns all items based on the first line of text inside them.
- last-baseline β Aligns all items based on the last line of text inside them.
123 some
thing align-items: last baseline-
123 some
thing align-items: flex-start-
123 some
thing align-items: flex-end-
123
align-items: start-
like
flex-startbut respect writing direction. align-items: endalign-items: center-
123
Less common values
xtodoalign-items: self-start-
effect right-to-left languages.
align-items: self-end-
effect right-to-left languages.
align-items: normal-
same as
stretchbut if the item has its own height or width set, or if it's a grid item, normal may fall back tostartinstead of stretching.
align-items: anchor-center-
align-items: anchor-center is a special value introduced with CSS Anchor Positioning.
It aligns the flex/grid items (or absolutely positioned elements) to the center of their associated anchor element along the block axis (usually vertical).
This is very useful when you have an element positioned via anchor positioning (like a tooltip, popover, or floating panel) and you want it perfectly centered on its anchor.
In the case of anchor-positioned elements, aligns the items to the center of the associated anchor element in the block direction. See Centering on the anchor using anchor-center.
align-items: safe center-
123 some
thing
align-items: unsafe center-
123 some
thing
safe-
Used alongside an alignment keyword. If the chosen keyword means that the item overflows the alignment container causing data loss, the item is instead aligned as if the alignment mode were start.
unsafe-
Used alongside an alignment keyword. Regardless of the relative sizes of the item and alignment container and whether overflow which causes data loss might happen, the given alignment value is honored.