Back to Lessons

CSS Flexbox Layout

April 5, 2026

Flexbox One-Dimensional Layout

Perfect for navigation bars, card layouts, centering.

Flex Container Properties

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

Flex Item Properties

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

Common Patterns

  • center: justify-content: center; align-items: center
  • navbar: justify-content: space-between
  • cards: flex-wrap: wrap; gap: 20px