Align Self In Tailwind CSS
In this article, we will explore what Tailwind align self is, how it works, and how to use it effectively in your web development projects.
The align-self class in Tailwind CSS provides a quick and easy way to set the align-self property.
Tailwind align self aligns an individual flex item along the cross-axis (vertical axis) of a flex container.
Tailwind align-self lets you specify the vertical alignment of a flex item in conjunction with a flex container.
Tailwind Align Self: how does it work?
The align-self property can be assigned to any flex item, such as a div or an image.
This property determines how a flex item is aligned vertically within a flex container.
When a container is set to display: flex and flex-direction: row, the align-self property can be used to align flex items vertically.
Tailwind CSS supports the following align-self values:
- auto – This value allows the flex container to decide how the flex item should be aligned.
- start – Positions the flex item at the start of the cross-axis.
- End – Positions the flex item at the cross-axis end.
- Center – Aligns the flex item at the cross-axis center.
- baseline – Sets the flex item’s baseline to the flex container’s baseline.
- Stretch – Fills the container to the full height of the flex item.
Tailwind Align Self-auto
Align-auto inherits the align-items property of its parent container.
It inherits stretched as a default value if it does not have a parent container.
You can assign the align-self class to any flex item within a flex container by combining the align-self keyword with the desired value:
Tailwind Align Self-start
When used with a flex container, align-self-start aligns a flex item to the top of the cross-axis.
Text, images, and other elements can be aligned to the top of a container when the default alignment is not preferred.
Flex items can be aligned to the top of a container by adding the class align-self-start:
Tailwind Align Self-end
An align-self-end property aligns a flex item to the end of the cross-axis of a flex container.
Flex items will appear in flex-direction of column at the bottom of the container, or on flex-direction of row at the right of the container:
Tailwind Align Self-center
The align-self-center property aligns a flex item vertically in the center of the container.
You can align flex items to the center of a container by adding the class align-self-center:
Tailwind Align Self-baseline
By setting the align-self property to baseline, the align-self property of an item aligns with the baseline of a flex container.
You can use this if you want to align items with different font sizes and line heights along a common baseline.
Tailwind Align Self-stretch
An align-self-stretch property stretches flex items across the cross-axis to their full height.
To stretch a flex item to the full height of the container, add the align-self-stretch class: