liveBook · Manning

Cross axis

As explained in Web Design Playground, Second Edition

The cross axis is the direction perpendicular to the main axis in a flex container.

A Flexbox container has two directions, or axes. The main axis runs along its flex items; the cross axis runs across them, at a right angle. Think of a row of items: the row runs horizontally, so its cross axis runs vertically. Change the row to a column, and the cross axis runs horizontally instead. section 12.2

Set `display: flex` on a container to make its children flex items. Then `flex-direction` determines which way the main axis runs. For alignment, ask two separate questions: Where should items sit *along* the main axis? Use `justify-content`. Where should they sit *across* it? Use `align-items`. section 12.2

Center a header across its row

A header can put a logo and title side by side with `display: flex`. Add `align-items: center` to center them on the cross axis—which is vertical for this horizontal row. The names sound abstract, but the visible result is simply a tidier header. section 12.6

If items wrap onto multiple lines, there is one more cross-axis question: how should those lines be arranged? That is the job of `align-content`. First decide the item direction, then tackle alignment; the axes will be much less mysterious. section 12.2

How Web Design Playground, Second Edition covers it

How deep it goes
Defines both axes and identifies the properties used for item and line alignment, without descending into browser internals.
Examples
Uses a horizontal header whose logo and title are centered on the vertical cross axis.
What it assumes
Introduces flex containers and defines both axes without assuming previous Flexbox knowledge.
What you can do after
Operate/configure it with CSS Flexbox to choose cross-axis alignment for items and wrapped lines.
How it connects
Connects flex-direction, justify-content, align-items, flex-wrap, and align-content to Flexbox layout.

Also explained in

Compare how 3 books explain cross axis →

Related concepts

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