Stretch flex items if align-self
resolves to stretch
Flex items have a final say, but they can ask the flex container what to do
This is why the title of the chapter says that we need to check if align-self
resolves to stretch
.
We say “resolve” because align-self
either has a specific value, or has auto
and listens to the flex container’s value.
By default, flex items listen to their parent aka flex container
The initial value of align-self
is auto
, which means each flex item uses the value suggested by the flex container’s property.
By default, the flex container suggests to its flex items that they stretch.
The initial value of is
normal
.
can be used in different types of layout, and
normal
might mean different things in those other layout types.
But in Flexbox, normal
is the same as stretch
.
So, each flex item says “my align-self
is auto
, so I’ll use the flex container’s : normal
”.
This stretching can happen no matter if the flex container allows wrapping or not.
Flex lines would only get stretched if the flex container allowed multiple flex lines in the first place.
The situation here is different, because the flex items can always have different sizes and they don’t care if other flex lines exist or not.
If a flex item that gets stretched has an aspect ratio, then this will affect its size in the main axis.
For example, this happens when you stretch an img
element.
The browser tries to prevent the image from being squished, so it has to make the flex item bigger in the main axis.
Wait, I thought we calculated the main size already?
Yeah, this part is a little weird.
What happens is the flex item already knows ahead of time that it will be doing this stretching. So it requests a flex base size that accounts for this in that earlier step.