Why setting 100% height
on child (.inner
) of flex item works? For every element in this code height
is "set" to auto
.
Since the beginnings of CSS in the 1990s, a percentage height on an in-flow child element has required a defined height on the parent element. Otherwise the child defaults to height: auto
.
The only acceptable height reference on the parent has come from the height
property. Other forms of height, such as min-height
and max-height
, have been invalid for this purpose.
Although the spec has never explicitly specified that the parent must use the height
property – only the generic work "height" has been used – using the height
property has become the traditional interpretation and predominant implementation across browsers.
In recent years, however, browsers have broadened their interpretation of spec language to include other forms of height, such as flex-basis
.
So, in 2017, it's not surprising that height: 100%
does not resolve to height: auto
in all cases where the parent has no specified height
.
Today's browsers may also seek a height reference from flex-grow
, flex-basis
, align-items
or something else.
Here a some more details about the height
property and percentage values:
And then there are interventions:
An intervention is when a user agent decides to deviate slightly from a standardized behavior in order to provide a greatly enhanced user experience.
This is browsers makers basically saying: "Thanks for the spec guidance, but we know our users and we can do better." So they go off-script hoping to be more thoughtful and intuitive.
Here are several examples of possible Chrome interventions:
So, between interventions and a broader interpretation of the rules, height: 100%
may give full height even when the parent has no height
defined.
How do .inner
elements know that 100% height is the height of the highest flex child (.col-4
) in a row?
They don't. They just stretch to the height of the container, who's height is set by the tallest item in the row.