Understanding the flexbox layout algorithm is key. In this scenario, remember the following:
Mastering Flexbox Layout - Section 5: Utilizing Auto Margins
Auto margins on flex items behave similarly to those in block flow:
When calculating flex bases and flexible lengths, treat auto margins as zero.
Prior to alignment via justify-content
and align-self
, any excess free space is allocated to auto margins in that direction.
In your specific case, the remaining space is evenly distributed on both sides of the element. Here's another insight from the layout algorithm:
The ABCs of Flex Layout Algorithm - Chapter 7: Alignment on the Main Axis
Distribute any leftover free space. For each flex line:
If there is surplus positive space and at least one main-axis margin on this line is set to auto, divide the space equally among these margins. If not, reset all auto margins to zero.
Align the items along the main axis according to justify-content rules.