Learn HTML and CSS: The cross axis
Align-items
On the big square in front of the stage there's room in height. But as soon as the trucks are flex items, they all stretch from top to bottom. "My ice cream van isn't a block of flats," Nadia laughs.
The cross axis
Across the main axis runs the cross axis: in a row, that's from top to bottom. With align-items on the container you choose where the items stand on that axis.
The default is stretch: every item stretches to the full height of the container. With flex-start they stand at the top, with flex-end at the bottom, with center in the middle, and with baseline the first line of text of every item sits on one line.
A handy pair: justify-content works along the main axis, align-items along the cross axis.
.square { display: flex; align-items: center;}Try it yourself
Put the trucks together in the middle of the square, across and in height.
.square { display: flex;}<link rel="stylesheet" href="style.css"><main> <section class="square tall"> <div class="truck chips">Chips</div> <div class="truck ice-cream">Ices</div> <div class="truck pizza">Pizza</div> </section></main>body { margin: 0; font-family: system-ui, sans-serif; background: #fff8ec; color: #2b2118;}header { padding: 12px 16px; background: #264653; color: #ffffff;}header h1 { margin: 0; font-size: 1.5rem;}nav a { padding: 6px 10px; border-radius: 999px; color: #ffffff; text-decoration: none;}main { padding: 0 16px 24px;}.slogan { margin: 16px 0 0;}.square { margin: 16px 0; padding: 12px; border-radius: 18px; background-color: #efe6d4; background-image: radial-gradient(rgb(110 90 60 / 0.16) 1px, transparent 1.5px); background-size: 14px 14px; box-shadow: inset 0 0 0 1px rgb(110 90 60 / 0.14);}.square.tall { height: 200px;}.square.narrow { max-width: 250px;}/* A striped awning and two wheels: only for the look. */.truck { position: relative; margin-bottom: 6px; padding: 16px 14px 12px; border-radius: 10px 10px 8px 8px; background-color: #e76f51; background-image: repeating-linear-gradient(90deg, rgb(255 255 255 / 0.85) 0 7px, transparent 7px 14px); background-size: 100% 7px; background-repeat: no-repeat; box-shadow: 0 1px 1px rgb(43 33 24 / 0.12), 0 6px 12px -6px rgb(43 33 24 / 0.35); color: #ffffff; font-weight: 700;}.truck::before,.truck::after { content: ""; position: absolute; bottom: -5px; width: 10px; height: 10px; border-radius: 50%; background: #d9cfbb; box-shadow: inset 0 0 0 3px #2b2118;}.truck::before { left: 9px;}.truck::after { right: 9px;}.chips { background-color: #e9c46a; color: #3a2a00;}.taco { background-color: #e76f51;}.pizza { background-color: #2a9d8f;}.waffle { background-color: #9c6644;}.ice-cream { padding-top: 30px; padding-bottom: 26px; background-color: #f4a6c6; color: #4a1030;}.curry { background-color: #f4a261; color: #3a1f00;}.burger { background-color: #6d597a;}.soup { background-color: #588157;}.card { padding: 4px 16px; border-radius: 12px; background: #ffffff; box-shadow: 0 1px 2px rgb(43 33 24 / 0.08);}.card h2 { font-size: 1.15rem;}footer { padding: 12px 16px; background: #264653; color: #ffffff;}Every numbered item belongs on the dashed outline with the same number.
Ready for more?
The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson