Μετάβαση στο κύριο περιεχόμενο
← 🎨 CSS as a design system·Ενότητα B2 · Μάθημα 3
ΕργασίαThree divs A/B/C inside a .row container. Apply display: flex to .row so they line up horizontally. Each child has padding 12px and a background color (#fee, #eef, #efe respectively).

Flexbox: οθόνη: flex στο γονικό

100 XP8 min
Θεωρία

One declaration opens everything

.container { display: flex; }

The container becomes a "flex container." Its DIRECT children become "flex items" — they flow horizontally (row by default), shrink to fit, and align together as a unit.

Before vs after

<div class="row">
  <div>A</div>
  <div>B</div>
  <div>C</div>
</div>
  • Without flex — three vertical divs (block default).
  • With `.row { display: flex }` — three divs side-by-side, all the same height (taller children stretch the others to match).

The two axes

A flex container has a main axis (default: horizontal, left→right) and a cross axis (perpendicular, default: vertical).

  • justify-content aligns items along the MAIN axis (where they sit horizontally).
  • align-items aligns items along the CROSS axis (how they're aligned vertically).

We'll dive deep into both over the next few lessons.

Inline-flex vs flex

display: flex makes the container itself a block element. display: inline-flex makes the container inline (sits in text flow) while still flexing its children. 99% of the time use flex, not inline-flex.

🔒

Εγγράψου για να αρχίσεις να προγραμματίζεις

Η θεωρία είναι ανοιχτή για όλους. Ο επεξεργαστής, η ζωντανή προεπισκόπηση και ο έλεγχος ξεκλειδώνουν με 7-ήμερη δωρεάν δοκιμή — απαιτείται κάρτα.

Εγγραφή — δωρεάν δοκιμή →

Τα πρώτα 10 μαθήματα κάθε διαδρομής είναι δωρεάν. Δεν χρειάζεται κάρτα.

← ΠροηγούμενοΕπόμενο μάθημα →

Μια συμβουλή Python ή web την ημέρα — με email

Σύντομο, γραμμένο στο χέρι, χωρίς spam. Διαγραφή με ένα κλικ.