main axiscross axisline 1line 21.row {2 width: 600px;3 height: 160px;4 display: flex;5 gap: 16px;6 justify-content: space-between;7 align-items: center;8 flex-wrap: wrap;9}10.b { flex-grow: 1; }1<div class="row">2 <div class="a">A</div>3 <div class="b">B</div>4 <div class="c">C</div>5</div>.a100 × 40.b140 × 70.c100 × 30flex16pxspace-betweencenter1300pxwrap
Front: the two files, style.css (the .row rule) and index.htmlBack: the flex container .row and its three boxes, drawn 1 unit per CSS pxTokens: each CSS value on its way from the card to the containerBack: the flex container .row (600 × 160 CSS px) on its page, with the boxes .a, .b and .c, and the main and cross axes. Front: style.css and index.html. Each CSS line switches on in turn and the boxes move to where a browser puts them: a row, 16px gaps, space-between, centred, b growing, all three shrinking at 300px, and c wrapping to a second line. Before align-items is set, its default (normal, which acts as stretch) makes items as tall as the row only when their height is auto. These boxes have a set height, so they stay at the top.

Turning flex on

  1. The HTML puts three boxes, a, b and c, inside a div with the class row. Without flexbox they follow normal flow: each div is a block box, so it starts on a new line and they stack top to bottom.

Placing the items

Sharing space

What happens

;; step 1/9 · normal-flow
.row   600px × 160px, display: block
  .a   100px × 40px   y 0
  .b   140px × 70px   y 40
  .c   100px × 30px   y 110
normal flow: one box under the next

The card leaves out the boxes' sizes. The full style.css also has .a { width: 100px; height: 40px; } .b { width: 140px; height: 70px; } .c { width: 100px; height: 30px; } Before align-items is set, its default (normal, which acts as stretch) makes items as tall as the row only when their height is auto. These boxes have a set height, so they stay at the top.