Skip to main content

Complete CSS Flexbox Tutorial for Beginners in 2 Hours

freeCodeCamp.orgNovember 24, 20252h 14min23,853 views
102 connections·40 entities in this video→

Understanding CSS Flexbox

  • πŸ’‘ CSS Flexbox is a layout model that transforms containers into flexible boxes, allowing precise control over child elements called flex items.
  • πŸš€ It simplifies creating complex layouts and responsive web pages, reducing the need for hacks like floats and margins.
  • βœ… Key benefits include easy alignment and centering, developing responsive layouts with fewer media queries, reordering elements without changing HTML, and creating same-height columns.

Core Flexbox Concepts

  • πŸ—ΊοΈ The main axis and cross axis determine the direction of content flow (row or column) and are fundamental to Flexbox.
  • ↔️ display: flex or display: inline-flex on a container makes it a flex container, enabling Flexbox properties for its children.
  • πŸ”„ flex-direction controls the main axis (row, row-reverse, column, column-reverse).
  • πŸ“¦ flex-wrap determines if items wrap onto multiple lines when they exceed container width (nowrap, wrap, wrap-reverse).
  • ↔️ flex-flow is a shorthand for flex-direction and flex-wrap.

Alignment and Spacing Properties

  • 🎯 justify-content aligns items along the main axis (flex-start, flex-end, center, space-between, space-around, space-evenly).
  • 🎯 align-items aligns items along the cross axis (stretch, flex-start, flex-end, center, baseline).
  • 🎯 align-content distributes space between lines along the cross axis when there are multiple lines (flex-start, flex-end, center, space-between, space-around, space-evenly).
  • 🧩 place-content is a shorthand for align-content and justify-content.
  • πŸ‘€ align-self overrides align-items for individual flex items.

Item Sizing and Ordering

  • πŸ“ flex-grow determines how much an item can grow relative to others if there's extra space.
  • πŸ“‰ flex-shrink determines how much an item can shrink relative to others if there's not enough space.
  • πŸ“ flex-basis sets the initial main size of a flex item before free space is distributed.
  • πŸ› οΈ flex is a shorthand for flex-grow, flex-shrink, and flex-basis (e.g., flex: 1 1 auto).
  • πŸ”’ order property allows reordering flex items visually without changing HTML structure, useful for accessibility.

Spacing and Practical Examples

  • ↔️ gap (or row-gap, column-gap) adds spacing between flex items.
  • βœ… Centering an element is achieved by setting display: flex, justify-content: center, and align-items: center on the container.
  • πŸ—οΈ Building a navigation bar demonstrates nesting flex containers and using properties like justify-content: space-between and align-items: center for layout.
Knowledge graph40 entities Β· 102 connections

How they connect

An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.

Hover Β· drag to explore
40 entities
Chapters20 moments

Key Moments

Transcript487 segments

Full Transcript

Topics21 themes

What’s Discussed

CSS FlexboxLayout ModelResponsive DesignFlex ContainerFlex ItemsMain AxisCross Axisjustify-contentalign-itemsflex-directionflex-wrapflex-growflex-shrinkflex-basisflexorderalign-selfalign-contentplace-contentgapNavigation Bar
Smart Objects40 Β· 102 links
PersonΒ· 1
ConceptsΒ· 36
CompanyΒ· 1
MediasΒ· 2