I am trying to get my mind around flex box layout and now considering flex-direction: column
option.
HTML
<div class="container">
<div class="item">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat similique nihil, mollitia
voluptates iste eos atque unde repellendus iure voluptatibus nulla explicabo laboriosam, harum, eum dicta.
Maiores quia aliquid in.</div>
<div class="item">
Lorem
</div>
</div>
CSS
.container {
display: flex;
flex-direction: column;
}
.item{
flex: 1;
}
As long as our screen displays the first item div
's text in multiple rows, the items end up with different main sizes (heights). It was rather surprising to me as row flex-direction in this case would hold the same main sizes of items (widths).
To find out how it happens, I delved into the spec.
9.2. Line Length Determination
2 Determine the available main and cross space for the flex items. For each dimension, if that dimension of the flex container’s content box is a definite size, use that; ... otherwise, subtract the flex container’s margin, border, and padding from the space available to the flex container in that dimension and use that value. This might result in an infinite value.
4 Determine the main size of the flex container using the rules of the formatting context in which it participates.
As far as I'm concerned, it is the very case when the available space in the main (vertical) dimension is an infinity value. So it puzzles me how it's possible to determine the container's main size (step 4), noting that sizes of the items are still uncalculated at this point (the container is a block element, so its height value is dependent on its children).
Can anybody provide some explanation and point me out to the place in the spec where our items finally get different height values?1
1: In accordance with the step 4 of 9.7. Resolving Flexible Lengths, main size of an item should be a fraction of its grow factor to the sum of the items' grow factors multiplyed by the free space (the container's height). We have the same grow factors, so why do we see different items heights?