HomeGuideLabGlossary

Get hypothetical cross size of flex items

We have the main size, now we need the cross size

As you saw in the previous chapter, figuring out the size of a flex item in the main axis lies at the heart of Flexbox layout. The flex items have complete control over how they agree to be sized.

1212We decide if we’ll growOr shrinkflex-growflex-shrink

Sizing flex items in the cross axis is a little different. For one, the Flexbox-related properties like flex-grow or flex-basis have no direct effect on the cross size of flex items. Instead, we’ll get the size of our flex item by looking at its sizing property that corresponds to the cross axis. For example, if you have a row flex container and you’re writing in English, then the main axis is horizontal and the cross axis is vertical. So the property that determines the cross size of the flex items would be height.

1main directioncross directionheight

This size is called hypothetical because it might change later

That’s because flex lines and flex items can be stretched after we get this size, so it can still change. That’s why we call it hypothetical.

What a nice dayWhat a nice dayheight: autoHypotheticalsizeMight get stretched lateralign-self: stretch

For example:

Oh hiOh hiWhat a nice little longer sentence you have here!height: auto
Oh hiOh hiWhat a nice little longer sentence you have here!align-self: stretchalign-self: center

Determining the cross size

  1. Take the main size of the flex item, and the cross-axis space made available by the flex container.
What a nice little longer sentence you have here!height: autoCross space available: infiniteMain space available
  1. Lay out the contents of the flex item in a rectangle created by the two sizes mentioned above.
What a nice little longer sentence you have here!
  1. Note the cross size you end up with as the hypothetical cross size of the flex item.
What a nice little longer sentence you have here!What a nice little longer sentence you have here!Hypothetical cross size