🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

Guia completo do CSS Flexbox 2026: layouts, padrões e exemplos reais

⏱️3 min read  ·  602 words

CSS Flexbox ainda é a ferramenta de layout mais importante para componentes de UI em 2026. Enquanto CSS Grid lida com layouts bidimensionais, Flexbox se destaca em alinhamento unidimensional, barras de navegação responsivas, layouts de cartão e elementos de centralização. Este guia completo cobre todas as propriedades com exemplos visuais.

Propriedades do contêiner flexível

.container {
  display: flex;          /* or inline-flex */
  flex-direction: row;    /* row | row-reverse | column | column-reverse */
  flex-wrap: nowrap;      /* nowrap | wrap | wrap-reverse */
  flex-flow: row nowrap;  /* shorthand: flex-direction + flex-wrap */

  /* Main axis alignment (row = horizontal, column = vertical) */
  justify-content: flex-start;   /* flex-start | flex-end | center | space-between | space-around | space-evenly */

  /* Cross axis alignment */
  align-items: stretch;          /* stretch | flex-start | flex-end | center | baseline */

  /* Multi-line cross axis alignment (only when flex-wrap: wrap) */
  align-content: normal;         /* normal | flex-start | flex-end | center | space-between | space-around | space-evenly | stretch */

  /* Gap between items */
  gap: 16px;             /* gap: row-gap col-gap */
  row-gap: 16px;
  column-gap: 24px;
}

Propriedades do item flexível

.item {
  /* flex-grow: how much to grow (0 = don't grow) */
  flex-grow: 1;          /* 0 = don't grow, 1 = grow proportionally */

  /* flex-shrink: how much to shrink (1 = shrink proportionally) */
  flex-shrink: 0;        /* 0 = don't shrink */

  /* flex-basis: initial size before growing/shrinking */
  flex-basis: 200px;     /* auto | 0 | 200px | 25% */

  /* Shorthand: grow shrink basis */
  flex: 1 1 auto;        /* flex: 1 (common) | flex: 0 0 200px | flex: auto */

  /* Self alignment (overrides align-items for this item) */
  align-self: center;    /* auto | stretch | flex-start | flex-end | center | baseline */

  /* Order: visual order (default: 0) */
  order: -1;             /* appears before order:0 items */
}

Padrões comuns de Flexbox

Centralização perfeita

/* Center anything horizontally and vertically */
.center-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* Or use margin: auto on the child (works when parent is flex) */
.centered-item {
  margin: auto;
}

Barra de navegação

<nav class="navbar">
  <a href="/" class="logo">TechPulse</a>
  <ul class="nav-links">
    <li><a href="/blog">Blog</a></li>
    <li><a href="/about">About</a></li>
  </ul>
  <a href="/contact" class="cta">Get Started</a>
</nav>

.navbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 64px;
}

.logo { font-weight: bold; }

.nav-links {
  display: flex;
  gap: 24px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;              /* push CTA to right */
  justify-content: center;
}

.cta { margin-left: auto; }  /* or use flex: 1 on nav-links

Layout de cartão com alturas iguais

.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.card {
  display: flex;
  flex-direction: column;
  flex: 1 1 300px;     /* grow, shrink, min-basis 300px */
  max-width: 400px;
  background: white;
  border-radius: 12px;
  padding: 24px;
}

.card-content {
  flex: 1;             /* grows to fill space, pushes button to bottom */
}

.card-button {
  margin-top: 16px;    /* always at bottom regardless of content height */
}

Rodapé pegajoso

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;             /* grows to fill remaining space, pushing footer down */
}

footer {
  /* Always at bottom */
}

Layout do Santo Graal

.layout {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.layout-header,
.layout-footer { flex: none; }

.layout-body {
  display: flex;
  flex: 1;
}

.layout-sidebar { width: 250px; flex: none; }
.layout-main    { flex: 1; }        /* fills remaining space */
.layout-aside   { width: 200px; flex: none; }

Layout responsivo com flex-wrap

/* Items stack vertically on mobile, go horizontal on desktop */
.responsive-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.responsive-item {
  flex: 1 1 250px;     /* min-width 250px, grows to fill */
}

/* Force break: half-width items */
.half-width {
  flex: 1 1 calc(50% - 16px);
  max-width: calc(50% - 16px);
}

/* Full-width override */
.full-width {
  flex-basis: 100%;
}

Flexbox vs Grid: quando usar cada um

Cenário Usar Flexbox Usar grade
Barra de navegação
Lista de cartas seguidas
Layout 2D complexo
Centralizar um elemento
Layout do formulário ✅ (simples) ✅ (complexo)
Layout da página (cabeçalho/principal/rodapé)
Posicionamento automático de itens

O domínio do Flexbox é essencial para qualquer desenvolvedor web. A combinação deflex: 1para itens crescentes,gappara espaçamento,align-itemspara alinhamento do eixo cruzado, eflex-wrap: wrappara layouts responsivos cobre 90% dos casos de uso do mundo real.

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇬🇧 English🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা