Flex Align Self in CSS - CN
Flex Align Self in CSS - CN
Overview
The align-self property is used for the alignment of selected flex items inside the flex
container. This overrides the default alignment set by the flex container.
● auto ( Default )
● flex-start
● flex-end
● center
● stretch
● baseline
CSS : .flex-container {
display:flex;
align-items: stretch ;
}
#div2{
align-self : flex-start ;
}
Browser :
❖ In general align-items were stretch but we did align-self as flex-start for 2nd div.
1
flex-end
The flex-end value aligns the selected flex items towards the end of the cross axis.
CSS : .flex-container {
display:flex;
align-items: stretch ;
}
#div2{
align-self : flex-end ;
}
Browser :
center
The center value aligns the selected flex items towards the center of the cross axis.
CSS : .flex-container {
display:flex;
align-items: stretch ;
}
#div2{
align-self : center ;
}
Browser :
2
stretch
The stretch value stretches the selected flex items to fill the container along the cross
axis.
CSS : .flex-container {
display:flex;
align-items: stretch ;
}
#div2{
align-self : stretch;
}
Browser :
baseline
The baseline value aligns the flex items such as the baselines of the content inside the
items. This means that the bottom base of the content inside the flex item will be the
axis to align the items.
To see this property work, we need to make some variation in the above code. The
changes are highlighted:
CSS : .flex-container {
display:flex;
align-items: stretch;
}
3
#div1{
align-self: baseline;
}
#div3{
align-self: baseline;
}
Browser :
Here, h2 is not given the baseline property. Therefore, it is not aligned and is
stretched by default.