Flexbox is a 1D layout system for aligning items horizontally or vertically.
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
▶ Main-axis → defined by flex-direction (row = horizontal, column = vertical).
▶ Cross-axis → perpendicular to main-axis.
▶ flex-grow: how much item expands.
▶ flex-shrink: how much item shrinks.
▶ flex-basis: initial size before grow/shrink.
👉 shorthand: flex: grow shrink basis;
➡ Flexbox → 1D layout (row OR column).
➡ Grid → 2D layout (rows AND columns).
➡ Flexbox = content-first. Grid = layout-first.
CSS Grid is a 2D layout system with rows & columns.
.container {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
grid-gap: 10px;
}
▶ Explicit → defined with grid-template-rows/columns.
▶ Implicit → auto-created when extra items exist.
If items are not assigned to specific cells, grid auto-places them row by row or column by column.
➡ Absolute → relative to parent.
➡ Fixed → relative to viewport.
▶ Multi-column (column-count) → like newspaper text.
▶ Flexbox → linear arrangement.
▶ Grid → full 2D control.