Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Modern Layouts: Flexbox & CSS Grid 22 mins read Free Lesson

CSS Flexbox: Complete One-Dimensional Layouts

Master display flex, flex-direction, justify-content, align-items, flex-wrap, and flex item properties.

Why Flexbox?

Flexbox (Flexible Box Layout) is designed for 1-dimensional layouts (either a row OR a column) with automatic alignment and distribution of space.

.navbar-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between; /* Horizontal spacing */
    align-items: center;            /* Vertical centering */
    gap: 1.5rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

Key Flex Items Properties:

  • flex-grow: 1: Item expands to fill available remaining space.
  • flex-shrink: 0: Prevents item from shrinking below its base width.
  • flex-basis: Initial default size before remaining space is distributed.