WEMAXA.COM Design · Development · AI · Available worldwide
Studio / Wemaxa 01
Status Active Location Worldwide Focus Web + AI Delivery Remote Response < 1 Business Day
Tutorial 038Web Design & Development13 steps3 fixes

How to Create a Responsive Layout With Flexbox

A beginner guide to arranging navigation, buttons or cards in a flexible row/column that can wrap on smaller screens.

By the end: You will understand flex container versus flex item and create a wrapping layout without fixed thirds.

TARGET RESULTHow to Create a Responsive Layout With Flexbox

You will understand flex container versus flex item and create a wrapping layout without fixed thirds.

Key terms before you start

These definitions make the steps easier to follow and help distinguish controls, files and concepts that can look similar at first.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
CSSCascading Style Sheets; it controls presentation such as layout, spacing, color and responsive behavior.
CSS selectorThe part of a CSS rule that chooses the elements to style.
CSS propertyA named presentation setting such as display, gap, color, padding or width.
FlexboxA one-dimensional CSS layout system designed mainly around a row or column.
BreakpointA condition, commonly a viewport width, where a media query changes the layout.
Browser Developer ToolsBuilt-in browser tools for inspecting HTML/CSS, network requests, responsive layouts and console errors.

What you need before starting

  • A code editor
  • A local/staging web page you are allowed to edit
  • A modern browser with Developer Tools

Real-world notes from public discussions

These are tied to public discussions, not invented case studies. Open the source to read the full thread and surrounding replies.

r/webdev — CSS Grid or Flexbox?Open discussion ↗

The repeated developer rule is practical rather than ideological: Grid is useful for two-dimensional layout, Flexbox for arranging items along one main row/column, and real pages often combine both.

How it changes this tutorial: The CSS tutorials below choose layout tools according to the shape of the problem instead of declaring one tool universally better.
FULL TUTORIAL

Step-by-step tutorial

Every step is shown below. Work through them in order and use each checkpoint to confirm the result before moving on.

01
STEP 01 / 13

Work on a local or staging copy

Do this

Open the project containing the HTML/CSS source. If this is a production site, use a staging copy or backup before structural changes.

Why

A browser page is rendered from source files/CMS output; DevTools edits do not save back to the server.

HTMLHyperText Markup Language; it describes the structure and meaning of web content.
IF THIS GOES WRONGDevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

CHECKPOINTYou know which source file/template controls the page.
02
STEP 02 / 13

Open the page in a modern browser

Do this

Load the page, then press F12 or Ctrl+Shift+I (Windows/Linux) to open Developer Tools.

Why

DevTools lets you inspect the DOM, applied CSS, computed sizes, requests and console errors.

Browser Developer ToolsBuilt-in browser tools for inspecting HTML/CSS, network requests, responsive layouts and console errors.
IF THIS GOES WRONGA CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

CHECKPOINTDevTools is open beside the page.
03
STEP 03 / 13

Create one flex parent

Do this

Place the items in a parent such as <div class="row">.

Why

Flexbox controls the parent’s direct children.

FlexboxA one-dimensional CSS layout system designed mainly around a row or column.
CHECKPOINTThe intended items are siblings.
04
STEP 04 / 13

Enable Flexbox

Do this

Add display:flex to the parent.

Why

The default main axis is a row.

FlexboxA one-dimensional CSS layout system designed mainly around a row or column.
CHECKPOINTItems align in one row if space allows.
05
STEP 05 / 13

Allow wrapping

Do this

Add flex-wrap:wrap.

Why

Without wrapping, children may shrink too far or overflow.

IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTItems move to another row as width decreases.
06
STEP 06 / 13

Add spacing with gap

Do this

Add gap:1rem.

Why

Gap works for flex rows/columns and is easier than per-item margins.

CSSCascading Style Sheets; it controls presentation such as layout, spacing, color and responsive behavior.
CHECKPOINTWrapped rows retain consistent spacing.
07
STEP 07 / 13

Set a flexible basis

Do this

On children use flex:1 1 14rem or another content-tested basis.

Why

The values mean grow, shrink and flex-basis.

CHECKPOINTItems share available space but wrap before becoming too narrow.
08
STEP 08 / 13

Choose alignment

Do this

Use align-items for the cross axis and justify-content for the main axis only when needed.

Why

Do not use space-between to fake margins for complex wrapping rows without testing.

IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTAlignment remains sensible after wrapping.
09
STEP 09 / 13

Switch direction for a component if necessary

Do this

Use flex-direction:column for stacked variants or at a content-driven media query.

Why

Direction changes the main axis.

BreakpointA condition, commonly a viewport width, where a media query changes the layout.
CHECKPOINTThe component order remains logical.
10
STEP 10 / 13

Use Flex overlay

Do this

Enable the Flexbox badge/overlay in DevTools if available.

Why

Inspect axis, gaps and item sizes rather than guessing.

FlexboxA one-dimensional CSS layout system designed mainly around a row or column.
IF THIS GOES WRONGA CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

CHECKPOINTThe browser reports expected flex item sizes.
11
STEP 11 / 13

Test long text

Do this

Replace one item title with a long realistic string.

Why

Text length is a more useful stress test than empty demo boxes.

IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTNo item forces viewport overflow.
12
STEP 12 / 13

Test the public/staging URL logged out

Do this

Open the final URL in a private/incognito window.

Why

CMS/admin sessions can hide caching, permission or styling differences.

IF THIS GOES WRONGThe page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

CHECKPOINTThe visitor view matches the intended result.
13
STEP 13 / 13

Document the changed file/rule

Do this

Record the file/template/component and purpose of the change in the project notes or version-control commit.

Why

Future maintainers should not have to reverse-engineer why a rule exists.

CSS selectorThe part of a CSS rule that chooses the elements to style.
IF THIS GOES WRONGDevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

CHECKPOINTThe change has a traceable reason/location.
CONCRETE EXAMPLERule

Test the rendered page, not only the source code.

Concrete examples

RuleTest the rendered page, not only the source code.

Copyable example

Wrapping Flexbox
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.item {
  flex: 1 1 14rem;
  min-width: 0;
}

Troubleshooting

DevTools change disappears

Expected: DevTools edits are temporary. Copy the tested change into the real source/CMS and save it.

The page overflows only with long content

Test realistic/long content and fix intrinsic sizing/wrapping rather than designing around short demo text.

A CSS rule does not apply

Inspect specificity/order/inheritance in DevTools before adding !important.

FINAL CHECKDocument the changed file/rule

The change has a traceable reason/location.

Public discussion excerpts

How the topic comes up in practice

Short excerpts from public discussions that directly relate to the task. Use the source link for the complete context.

“Every card that would cause an overflow will be pushed into the next row while not wasting any space.”

responsive CSS Grid problem ↗

Documentation and references

Use these primary and supporting sources to verify current controls, browser behavior and product-specific details.