Skip to lesson content
Web Technologies › Level 13
LEVEL 13 · CSS

Flexbox, Grid and Responsive Design

Arrange content with clear axes, shared tracks and responsive changes learners can use.

↔️ Flexbox🗂️ Grid📱 Responsive🧪 Lab + MCQs
01

Learning Objectives

Flexbox

Arrange related items along a main axis with suitable sizing and wrapping.

Grid

Define tracks and place content in a consistent row/column arrangement.

Responsive design

Adapt to available space and test intermediate widths, not only named devices.

Usability

Keep readable content, meaningful order and visible keyboard focus.

02

Choose the Layout from the Task

One resource page, different layout tasks
Card collection · Grid

Shared columns organize the larger collection.

Card actions · Flexbox

Buttons share an axis and wrap when needed.

Reading text · Normal flow

Paragraphs grow naturally with the explanation.

03

Containers and Direct Items

<div class="actions">
  <button type="button">Inspect</button>
  <button type="button">Reset</button>
</div>

.actions { display: flex; gap: 12px; }
04

Flex Axes — Direction Changes the Question

.actions { display: flex; flex-direction: row; }
.steps { display: flex; flex-direction: column; }
Typical horizontal writing mode
row · main axis

Items progress along the inline direction.

column · main axis

Items progress along the block direction.

cross axis

Perpendicular to whichever main axis was chosen.

05

Flex Alignment — Space and Item Position

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
06

Wrapping and gap — Make Room for More Content

.actions { display: flex; flex-wrap: wrap; gap: 12px; }
.actions > button { flex: 0 1 auto; }
07

flex-grow, flex-shrink and flex-basis

.resource { flex: 1 1 140px; min-width: 0; }
.fixed-action { flex: 0 0 8rem; }
08

Minimum Sizes, Long Text and Source Order

.resource { min-width: 0; }
.resource .identifier { overflow-wrap: anywhere; }
09

Grid — Columns, Rows and Tracks

.resources {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
10

Grid Lines, Spans and Named Areas

.featured { grid-column: 1 / -1; }

.layout {
  display: grid;
  grid-template-areas: "main aside";
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 16px;
}
.main-panel { grid-area: main; }
.related-panel { grid-area: aside; }
11

fr, minmax and Content Constraints

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 16px;
}
12

auto-fit and auto-fill — A Responsive Track Pattern

.resources {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 16px;
}
13

Responsive Foundations — Viewport and Flexible Content

<meta name="viewport" content="width=device-width, initial-scale=1">

.page { width: min(100% - 2rem, 70rem); margin-inline: auto; }
img { max-width: 100%; height: auto; }
14

Media Queries — Change the Layout at a Useful Boundary

.resources { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 341px) {
  .resources { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 521px) {
  .resources { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
15

Reflow, Motion and Interaction Preferences

@media (prefers-reduced-motion: reduce) {
  .card-motion { transition: none; }
}
16

Premium Visualizer — Responsive Layout Journey

Follow the source order, grid choice and matching viewport rules. Use the same numbered timeline and playback controls as the previous lessons. The last stage asks you to verify content and keyboard use as well as the visual arrangement.

RESPONSIVE LAYOUT TRACE
Step 1 of 5
STEP 01

Begin with a meaningful source order

Six resource cards appear in document order 1 through 6.

HTML order: 1 → 2 → 3 → 4 → 5 → 6

What is happening?

A useful reading and keyboard sequence is the foundation. Layout must not be used to repair an illogical source order.

17

Premium Interactive — Layout and Viewport Lab

Default responsive Grid preview at 640px.

CSS supplied to the preview

18

Debugging — Explain the Layout Constraint

Container

Confirm the intended display value and which elements are direct items.

Size

Inspect basis, tracks, gaps, minimums and available container space.

Conditions

Check the actual viewport and which media-query rules match.

Behavior

Test reading sequence, keyboard focus, content growth and local scrolling.

19

Interview Questions — Flip to Explain

QUESTION

Why can a wrapped flex row look different from a grid row?

Click or press Enter to explain
ANSWER

Each flex line distributes its space independently. Grid can keep shared column tracks aligned across several rows.

QUESTION

Is justify-content always horizontal?

Click or press Enter to explain
ANSWER

No. In Flexbox it follows the main axis, which depends on direction and writing mode.

QUESTION

What is the difference between align-items and align-content?

Click or press Enter to explain
ANSWER

Align-items concerns items in a line; align-content concerns the distribution of lines in a multi-line flex context with relevant extra space.

QUESTION

Does flex-basis guarantee the final width?

Click or press Enter to explain
ANSWER

No. It supplies a starting size before growth, shrinking and constraints determine the result.

QUESTION

What does minmax(0, 1fr) help address?

Click or press Enter to explain
ANSWER

It gives the track a zero lower bound instead of an automatic minimum. The item’s content and overflow still need appropriate handling.

QUESTION

How do auto-fit and auto-fill differ?

Click or press Enter to explain
ANSWER

Auto-fit can collapse eligible empty repeated tracks after placement; auto-fill keeps generated slots. With no empty slots their result may look similar.

QUESTION

Does changing CSS order repair keyboard order?

Click or press Enter to explain
ANSWER

No. Put the meaningful sequence in the HTML and verify the actual reading and focus paths.

QUESTION

How should a breakpoint be chosen?

Click or press Enter to explain
ANSWER

Choose where the content needs a useful layout change and test around that boundary, rather than assuming one universal device size.

20

MCQ Practice — Explain the Arrangement

PRACTICE

1. Which elements normally become items when a container uses display: flex?

PRACTICE

2. In a typical horizontal writing mode with flex-direction: column, which axis is the main axis?

PRACTICE

3. Which property aligns flex items on the cross axis?

PRACTICE

4. What allows a flex collection to create additional lines?

PRACTICE

5. In flex: 1 1 140px, what is 140px?

PRACTICE

6. What does repeat(3, minmax(0, 1fr)) request here?

PRACTICE

7. What does 1fr refer to?

PRACTICE

8. Which can help an item shrink when an automatic minimum is the problem?

PRACTICE

9. What can auto-fit do after placement that auto-fill does not do in the relevant case?

PRACTICE

10. At 420px, which column count is expected in this lab’s responsive Grid?

PRACTICE

11. Does CSS visual reordering automatically produce a logical keyboard order?

PRACTICE

12. Which is a useful responsive test?

21

Extra Practice — Compare Specific Cases

Axes

  • Change a row to a column.
  • Expected: the main axis changes; explain alignment using axis names rather than only horizontal/vertical.

Wrap comparison

  • Use six fixed 140px items with gaps, then compare wrapping and non-wrapping.
  • Expected: the non-wrapping case needs enough width or access to overflow.

Shared tracks

Use a three-column grid with six cards. Expected: two rows share the same column structure under the fixed-track example.

Viewport rules

Test responsive Grid at 240px, 420px and 640px. Expected: one, two and three columns respectively.

Boundary checks

  • Test just below and above the lesson’s 341px and 521px minimum-width conditions in a standalone browser example.
  • Expected: the matching rule changes at its boundary.

Long token

  • Place a long resource identifier inside a card with suitable wrapping.
  • Expected: it remains available without pushing the whole page wider.

Focus order

Tab through the six native disclosure summaries. Expected: source sequence 1–6 stays meaningful at each width.

Few-item grid

  • Compare auto-fill and auto-fit with fewer items than available tracks.
  • Expected: eligible empty tracks behave differently; describe the actual inspected result.
22

Quick Revision

Items: Container layout acts on direct items.
Axes: Flex direction defines main and cross axes.
Alignment: Name the axis and inspect free space.
Wrapping: Use wrapping where controls should create new lines.
Flex sizing: Basis, growth, shrinking and constraints determine sizes.
Grid: Shared tracks organize columns and rows.
Tracks: fr and minmax operate within a track sizing context.
Responsive: Choose conditions where content needs change.
Content: Long tokens and enlarged text must remain available.
Order: Preserve a meaningful source and keyboard sequence.
23

Glossary — Flip to Learn

TERM

Flex container

Click to see meaning
DEFINITION

Flex container

An element establishing a Flexbox layout for its items.

TERM

Main axis

Click to see meaning
DEFINITION

Main axis

The axis along which flex items are arranged, determined by direction.

TERM

Cross axis

Click to see meaning
DEFINITION

Cross axis

The axis perpendicular to the flex main axis.

TERM

Flex basis

Click to see meaning
DEFINITION

Flex basis

The starting main-size basis used during flex sizing.

TERM

Grid track

Click to see meaning
DEFINITION

Grid track

The area between adjacent grid lines, forming a row or column.

TERM

Fraction unit

Click to see meaning
DEFINITION

Fraction unit

A share of flexible grid space, written fr.

TERM

Media query

Click to see meaning
DEFINITION

Media query

A condition controlling when a set of CSS rules applies.

TERM

Breakpoint

Click to see meaning
DEFINITION

Breakpoint

A chosen condition boundary where the layout or presentation changes.

TERM

Viewport

Click to see meaning
DEFINITION

Viewport

The viewing area used by the relevant document’s media and layout context.

TERM

Reflow

Click to see meaning
DEFINITION

Reflow

The adaptation of content arrangement as available space or presentation changes.

24

Final Challenge — Responsive Resource Collection

25

Level 13 Complete?

Before marking complete, build a wrapping action group, a track-based collection and a responsive change you can explain. Test a long token and a keyboard path at more than one width. Completion is a local study milestone, not an assessment score.