freecoding.school100% FREE · NO SIGNUP
Grid CanyonISSUE #12 of 27

flex container · justify-content · align-items

FlexboVSThe Float Phantom
Flexbo saysjustify-content aligns items along the main axis; align-items aligns across it.

justify-content distributes items on the main axis: flex-start, center, space-between, space-around, space-evenly. align-items aligns on the cross axis. Together, center+center is the famous one-line centering trick.

Power-ups you unlock

The Float Phantom attacks — common mistakes

Boss battleCenter a box in a tall flex container, then switch to space-between for a navbar.

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>.c{display:flex;justify-content:center;align-items:center;height:160px;background:#140a28}.c div{background:#b388ff;color:#06040d;padding:16px}</style></head><body style="background:#06040d;padding:20px"><div class="c"><div>centered</div></div></body></html>
▶ Open the interactive comic issue
‹ Flex Container · Direction · Wrap · GapFlex Items · Grow · Shrink · Basis ›