How can I align one flex item differently from the rest?
Quick answer
Set the container’s shared alignment with align-items, then add align-self to the one flex item you want to position differently. For example, align-items: center with align-self: flex-end aligns that item at the cross-axis end while the others stay centered. The cross axis is perpendicular to the main axis, and its orientation changes with flex-direction. [S1]
The question, the details, the next step.
A practical checklist
Confirm the parent uses
display: flex.Set the default cross-axis alignment with the parent’s
align-items.Apply
align-selfto the specific flex item, not the parent.Check
flex-directionto identify the cross axis.If the item does not respond, check for an automatic margin on that axis.
A few more useful answers
Does `align-self` change the alignment of the other flex items?
No. It overrides the shared align-items alignment for the selected flex item; the other items keep the container’s setting. [S1]
Can I use `align-self` on a regular block element?
It applies to flex items, not ordinary block-level boxes. Check that the element is an item in the relevant flex container. [S1]
What if the item has an automatic margin on the cross axis?
In that case, align-self is ignored, so check for an automatic cross-axis margin if the override seems ineffective. [S1]
Sources
References used for this guide.
- [S1] MDN: Overriding flex-item cross-axis alignment with align-self developer.mozilla.org · Checked
