blense.
HomeFrontendCodeAINewsGuidesCheatsheetsAbout

Technology decoded, always.

A curated read on AI, product, and the culture behind the code. No noise, no hype.

blense.

Technology with focus. Stories about what innovation really changes.

Sections

FrontendArtificial IntelligenceCode & DevTech News

Blense

AboutRSSPrivacy policyTermsCookies
© 2026 Blense · blense.fun
Frontend

CSS Flexbox: The Guide for Those in a Hurry

Learn the pillars of CSS Flexbox in record time. A guide focused on the essential syntax and alignments you actually use daily, without fluff and straight to the code.

Gby Genildo SouzaMar 225 min read
CSS Flexbox: The Guide for Those in a Hurry

🎯 Key Concepts

  • Container (Parent): Element that receives display: flex;. Manages the layout of its children.

  • Item (Child): Elements directly inside the flex container. They are organized by the container.

  • Main Axis: Default direction of items (row by default, but can be column). Controlled by flex-direction.

  • Cross Axis: Perpendicular to the main axis. Controlled by align-items and align-content.

  • Flexibility: Ability of items to grow (flex-grow), shrink (flex-shrink) or have a base size (flex-basis).

Um diagrama que ilustra um container flex com vários itens. Setas indicariam o 'Eixo Principal' (horizontal por padrão) e o 'Eixo Cruzado' (vertical por padrão). O diagrama deveria rotular claramente o 'Container' e os 'Itens' filhos, mostrando a relação hierárquica e a orientação dos eixos.

📝 Essential Syntax

Um conjunto de pequenos diagramas ou ilustrações que demonstram visualmente os efeitos de diferentes valores para `justify-content` (como `flex-start`, `center`, `space-between`) e `align-items` (como `flex-start`, `center`, `stretch`) em um container com alguns itens. Cada diagrama teria um título com a propriedade CSS aplicada.
CSS
/* On the Container (Parent) */.flex-container {  display: flex; /* Defines as flex container */  /* Direction of items */  flex-direction: row; /* default: row (horizontal) */  /* flex-direction: column; vertical line (column) */  /* Line wrapping */  flex-wrap: wrap; /* allows line wrapping */  /* flex-wrap: nowrap; does not wrap (default) */  /* Shorthand for flex-direction and flex-wrap */  flex-flow: row wrap;  /* Alignment on the Main Axis */  justify-content: flex-start; /* start (default) */  /* justify-content: flex-end; end */  /* justify-content: center; center */  /* justify-content: space-between; space between */  /* justify-content: space-around; space around */  /* justify-content: space-evenly; space evenly */  /* Alignment on the Cross Axis (single line) */  align-items: stretch; /* stretches (default) */  /* align-items: flex-start; start */  /* align-items: flex-end; end */  /* align-items: center; center */  /* align-items: baseline; aligns by baseline */  /* Alignment on the Cross Axis (multiple lines) */  align-content: stretch; /* stretches (default) */  /* align-content: flex-start; */  /* align-content: flex-end; */  /* align-content: center; */  /* align-content: space-between; */  /* align-content: space-around; */}/* On the Items (Children) */.flex-item {  /* Item growth (factor) */  flex-grow: 1; /* occupies available space */  /* flex-grow: 0; does not grow (default) */  /* Item shrinkage (factor) */  flex-shrink: 1; /* shrinks if necessary (default) */  /* flex-shrink: 0; does not shrink */  /* Base size of the item before growing/shrinking */  flex-basis: auto; /* width/height of content (default) */  /* flex-basis: 100px; */  /* Shorthand for flex-grow, flex-shrink, and flex-basis */  flex: 0 1 auto; /* does not grow, shrinks, auto-base */  /* flex: 1; (equivalent to flex: 1 1 0%) */  /* flex: auto; (equivalent to flex: 1 1 auto) */  /* flex: none; (equivalent to flex: 0 0 auto) */  /* Individual order of items */  order: 0; /* default */  /* order: 1; */  /* Individual alignment on the Cross Axis */  align-self: auto; /* inherits from container (default) */  /* align-self: flex-start; */  /* align-self: flex-end; */  /* align-self: center; */}

⚡ Quick Commands

  • display: flex;: Makes the element a flex container.

  • justify-content: center;: Centers items on the main axis.

  • align-items: center;: Centers items on the cross axis (in a single line).

  • flex-direction: column;: Changes the direction of items to vertical.

  • flex-wrap: wrap;: Allows items to wrap to the next line/column.

  • flex: 1;: Item grows, shrinks, and has a base of 0 (great for filling space).

The elite dev's arsenal.
Tailwind CSS v4: A Complete Guide to the New Rewrite and Performance16 minCSS Animations: How to Build Performant, Professional Interfaces Without Messy Code17 minMicrofrontends with Angular and Nx: what nobody tells you15 minJavaScript Event Loop: The Heart of Non-Blocking Concurrency — Revisited in 20256 min

🔧 Use Cases

  1. Basic Case: Simple Horizontal and Vertical Alignment

    HTML
    <div class="container">  <div class="item">Conteúdo</div></div>
    CSS
    .container {  display: flex;  justify-content: center; /* Centers horizontally */  align-items: center;     /* Centers vertically */  height: 100vh; /* Example to see the effect */}
  2. Intermediate Case: Responsive Navigation Layout

    HTML
    <nav class="navbar">  <a href="#">Home</a>  <a href="#">Sobre</a>  <a href="#">Contato</a></nav>
    CSS
    .navbar {  display: flex;  justify-content: space-around; /* Distributes links equally */  flex-wrap: wrap; /* Allows line wrapping on smaller screens */  background-color: #eee;  padding: 10px;}.navbar a {  padding: 8px 15px;  text-decoration: none;  color: #333;}
  3. Advanced Case: Simple Grid System (3 flexible columns)

    HTML
    <div class="grid-container">  <div class="col">Coluna 1</div>  <div class="col">Coluna 2</div>  <div class="col">Coluna 3</div></div>
    CSS
    .grid-container {  display: flex;  flex-wrap: wrap; /* Allows columns to wrap */  gap: 20px;       /* Space between columns */}.col {  flex: 1 1 calc(33.333% - 20px); /* 3 columns, shrink, base of 1/3 minus the gap */  min-width: 250px; /* Columns don't get too small */  background-color: lightblue;  padding: 15px;  text-align: center;}/* For very small screens, one column per line */@media (max-width: 600px) {  .col {    flex: 1 1 100%;  }}

🚨 Common Pitfalls

  • display: flex; only works on the direct parent: Flexbox properties applied to the container only affect its direct children.

  • Height of the flex-container: For align-items: center; to work vertically, the container needs a defined height (e.g., height: 100vh; or a fixed value).

  • margin: auto; on flex items: Using margin: auto; on a flex item can be powerful for pushing other items or centering a specific item within the main/cross axis.

  • width and height vs flex-basis: flex-basis generally overrides width (on the main axis) and height (on the cross axis) on flex items. Use flex-basis to define the preferred initial size.

  • flex-wrap: nowrap; with overflow: If you don't use flex-wrap: wrap;, items will try to stay on a single line and may overflow the container.

Interactive quiz

Test your knowledge

Answer and check your understanding.

1. Which property turns an element into a flex container?
2. Which property centers items along the main axis?
3. Flexbox properties set on the container affect which elements?
Keep exploring
Want more content like this?

Check out other articles in the same vein and keep the momentum.

See more articles
#CSS#Flexbox

The elite dev's arsenal.

Stop Using useMemo Wrong: A Practical Guide to React Performance
Frontend

Stop Using useMemo Wrong: A Practical Guide to React Performance

Master React useMemo with this guide. Learn when to memoize, how to fix dependency array bugs, and why over-optimization can hurt your performance.

Genildo Souza · Jul 8 · 14 min
CSS Animations: How to Build Performant, Professional Interfaces Without Messy Code
Frontend

CSS Animations: How to Build Performant, Professional Interfaces Without Messy Code

Bring your web interfaces to life. Learn when to use CSS transitions versus keyframes and how to optimize your animations for peak performance.

Genildo Souza · Jul 4 · 17 min
Angular Micro-frontends: How to Scale Large Applications and Eliminate Monolithic Build Times with Module Federation
Frontend

Angular Micro-frontends: How to Scale Large Applications and Eliminate Monolithic Build Times with Module Federation

Discover how to break down large Angular monoliths using Module Federation to enable independent deployments and seamless team scaling.

Genildo Souza · Jun 21 · 10 min
In this article
  • 🎯 Key Concepts
  • 📝 Essential Syntax
  • ⚡ Quick Commands
  • 🔧 Use Cases
  • 🚨 Common Pitfalls