liveBook · Manning

Flex-direction

As explained in CSS in Depth, Second Edition

The CSS flex-direction property specifies the main-axis direction and ordering of flex items in a flex container.

The CSS flex-direction property sets a flex container’s main-axis direction and item order. The default row flows along the inline direction; column stacks items along the block direction, while row-reverse and column-reverse reverse those flows. section 4.3

Changing direction rotates the main axis and keeps the cross axis perpendicular. In a column flexbox, flex-basis, flex-grow, and flex-shrink govern height rather than width, but vertical growth only matters when the container has an externally determined height. section 4.3.1

Stacking and equalizing a sidebar

Use a nested flexbox when a sidebar’s tiles must fill the height established by a taller neighboring column: .column-sidebar { display: flex; flex-direction: column; gap: var(--gap-size); } .column-sidebar > .tile { flex: 1; } The outer layout determines the sidebar height; the inner column distributes that height between its tiles. Without this inner direction change, the tiles remain naturally stacked and may not reach the height of the main tile. section 4.3.1 section 4.3

Listing 4.9 Creating a flex column on the right
.column-sidebar {             #1
  flex: 1;                   #1
  display: flex;             #1
  flex-direction: column;    #1
  gap: var(--gap-size);      #1
}

.column-sidebar > .tile {
  flex: 1;                  #2
}

Inspect the complete sidebar rule and see how flex-direction: column combines with flex: 1 on the child tiles. section 4.3.1

A practical flexbox workflow is to identify the container and items, enable display: flex, choose a gap or flex-direction when needed, and then assign flex values to control sizing. section 4.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains axis rotation, nested containers, and height-dependent growth, while deferring broader alignment and spacing options.
Examples
Uses a two-column page with a taller main tile and vertically stacked sidebar tiles that must align at the bottom.
What it assumes
Assumes familiarity with flex containers and items, while establishing how display: flex and axis terminology govern the layout.
What you can do after
Apply it via CSS to stack, reverse, or redistribute flex items and to build height-filling nested layouts.
How it connects
Ties flex-direction to flexbox, the main axis, the cross axis, flex-grow, flex-shrink, flex-basis, and flex items.

Also explained in

Compare how 3 books explain flex-direction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.