HomeGuideLabGlossary

Stretch flex lines for multi-line : stretch

By default, the flex line is already the size of the flex container

only applies if the flex container allows flex items to wrap. The flex container controls this with the CSS property, and the initial value of that property is nowrap.

flex-wrap: nowrapINITIAL PROPERTY VALUENothing to align

nowrap means flex items can’t wrap into a new flex line if there’s not not enough room for them on the existing flex line. They all get forced on a single flex line, and if they overflow that flex line, the get asked to shrink.

1122Shrink, pleaseAlright

We say that if a flex container allows flex items to wrap, then it’s multi-line. It doesn’t matter if there actually are multiple flex lines or not. If the flex container allows wrapping, then it’s considered multi-line.

flex-wrap: wrap1Still technically a multi-line flex containerEven though right now it doesn’t have multiple flex lines

This can only happen if the flex container allows flex items to wrap with

The other values of are wrap and wrap-reverse. With both of these the flex container will allow its flex items to wrap as needed.

12Cool I get to wrap into a new flex line

When the flex container doesn’t allow wrapping, the flex line is the same size as the flex container.

When wrapping is allowed, the flex lines are sized based on the size of the flex items in those flex lines.

132

This stretching changes the hypothetical size of flex lines we calculated before

This is that “later step” we talked about before. We calculated this initial size of flex lines based on the size of flex items. But now, this size of the flex line might change if we do the stretching.

113322HypotheticalBecause it might change

Stretching happens when is stretch or normal

This has to be set on the flex container. The initial value is normal, which in Flexbox behaves like stretch.

align-content: normalalign-content: stretchINITIAL PROPERTY VALUEIn Flexbox, normal means stretch

The flex container’s own size has to be “definite” for the stretching to work

Remember how in Flow layout a paragraph of text gets taller the more text you add to it? This makes the height of the paragraph “indefinite”, because it depends on how much text there is.

What a nice day!What a nice little longer sentence you have here!height: autoWe can’t tell how tall the paragraph will be without measuring its contentSo the size of the paragraph is indefinite.

So you could have a flex container that is sized in the same way as the paragraph. The bigger your flex items, the bigger the flex lines, and the bigger the flex container.

What a nice day!What a nice little longer sentence you have here!height: auto

If you have a flex container that itself is a block-level box in Flow layout (this would happen, for example, if your flex container is a box generated by a main element that’s a child of the body element), then by default that box’s height would be based on the size of its content.

main.flex-containerbodyspan.flex-item"What a nice day!"height: autoheight: autoheight: auto

In this case you couldn’t tell the flex lines, or lines of text in a paragraph to stretch, because the size itself already depends on the size of that content.

What a nice little longer sentence you have here!align-content: stretchStretch what?The flex container is sized based on the text inside, and I’m the size of the flex container

So the size of this “container box” needs to either be fixed in some way, or it needs to depend on something else than the size of its content.

What a nice little longer sentence you have here!height: 170pxNow we’re talking!

Examples of when a flex container has a definite size to make the stretching work

Fixed size

Give your flex container a fixed size to make the stretching work. For example, height: 500px. If your flex lines are smaller than that, they’ll stretch.

height: 500px1

Grid items

Flex containers that are grid items already have a definite size.

1

Flex items

Flex containers that are flex items may have a definite size, too (I think).

1