Flexbox Layout Patterns

Demonstrates CSS Flexbox for one-dimensional layouts including centering, space distribution, wrapping, and responsive navigation patterns.

CssForm Validation

Code

snippet
/* Center content perfectly */
.center {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* Responsive navigation bar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem;
}

.navbar .menu {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* Holy grail layout */
.layout {
  display: flex;
  min-height: 100vh;
}

.layout .sidebar {
  flex: 0 0 200px;
}

.layout .main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Card grid with wrapping */
.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.card-grid .card {
  flex: 1 1 300px;
}

/* Sticky footer */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page .content {
  flex: 1 0 auto;
}

.page .footer {
  flex-shrink: 0;
}

/* Equal height columns */
.columns {
  display: flex;
  align-items: stretch;
  gap: 1rem;
}

.columns > * {
  flex: 1;
}