Skip to content
CSS3

Flexbox Layout

Align and distribute items along one axis with flexbox.

By EZ4Code Team
flexboxlayout

Code

.container {
  display: flex;
  flex-direction: row;       /* row | column | row-reverse */
  justify-content: space-between;  /* main-axis alignment */
  align-items: center;       /* cross-axis alignment */
  flex-wrap: wrap;
  gap: 16px;
}

.item {
  flex: 1 1 200px;           /* grow shrink basis */
  order: 2;
  align-self: flex-end;
}

/* Center anything with three lines */
.center {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

Explanation

Flexbox lays out items along a single axis controlled by flex-direction. justify-content aligns on the main axis, align-items on the cross axis, and the flex shorthand sets grow, shrink, and basis. It is the standard tool for one-dimensional layouts and centering.

More CSS3 Snippets