> cs·fundamentals
interview 0% 26m read
8.4 ★ core [B][J] 1 interview Q's

Layout & responsive thinking

How elements arrange and reflow across screens — the box model, flexbox vs grid, reading width, mobile-first — so you can describe a layout precisely enough to build.

Layout is how the pieces are arranged and how that arrangement reflows when the screen gets narrower. You don’t need to write CSS, but you do need to describe a layout precisely — “a two-column grid that stacks on mobile, content capped at a readable width” — so the AI builds the right structure instead of guessing. This chapter is the vocabulary of arrangement. (The mechanics — how the box model and grid actually render — are Module 5.)

Inside vs between: the box model

You don’t need to write it, but you need to say it. Every element is a box: content in the middle, padding as breathing room inside the border, the border, and margin as the gap to its neighbours. When a card feels cramped, you want more padding (inside). When two cards are touching, you want more margin (between). Naming which one you mean is the difference between one precise instruction and three rounds of “a bit more space… no, the other space.”

One dimension or two: flexbox vs grid

This is the one layout decision worth knowing by name. Flexbox lays things out in a single direction — a row or a column — and is ideal when items should flow and wrap: a toolbar, a row of tags, a navbar. Grid places things in rows and columns at once and is the tool for the overall page: a fixed sidebar beside fluid content, or a responsive gallery of cards. The rule of thumb: flex for a line of things, grid for a layout of regions.

On the left, five chips flowing in a wrapping row labelled flexbox. On the right, six cards arranged in a 3-by-2 grid labelled grid.flexbox · one axis, wrapsgrid · rows × columns
FIG 1 · flex (a line) vs grid (a layout) Flexbox flows items along one axis and wraps; grid places them into explicit rows and columns.

Mobile-first, and why text needs a leash

Design the narrow layout first, then use breakpoints to add columns and space as the screen grows. This beats the reverse — cramming a desktop layout onto a phone — because deciding what matters on a small screen forces real priorities, and expanding is easier than salvaging. The other half is reading width: on a wide monitor, a paragraph that spans the whole screen is exhausting to read, so cap text containers at ~65–75 characters. (This very page does exactly that — the prose has a max width while diagrams can run wider.)

Three device frames. Mobile shows sidebar stacked above content; tablet shows a narrow sidebar beside content; desktop shows the same wider.mobile · stackedtablet · side by sidedesktop · wider content
FIG 2 · one layout, three widths The same sidebar-and-content layout reflows: stacked on mobile, side-by-side on tablet, with a wider content area on desktop.

Name the archetype

Most screens are one of a handful of layouts. Naming the archetype gets you a correct skeleton in one sentence.

ArchetypeShapeGood for
Centered columnone capped-width column, centeredarticles, forms, marketing pages
Sidebar + contentfixed nav beside fluid contentapps, docs (like this site)
Dashboard grida grid of cards / widgetsanalytics, admin overviews
Master–detaila list pane + a detail paneemail, settings, inboxes
Card grida responsive gallery of equal cardsproducts, galleries, search results
“Build a master–detail layout that collapses to a single list on mobile” is a complete spec.
Five small wireframes side by side: a centered column, a sidebar plus content, a dashboard grid of cards, a master-detail list-and-pane, and a card grid.centeredsidebardashboardmaster–detailcard grid
FIG 3 · five layout archetypes Most screens are one of these. Name the archetype and the AI builds the right skeleton in one sentence.

01 Learning objectives

0 / 6 done

02 Curated reading

03 Knowledge check

knowledge check3 questions · pass ≥ 70%
  1. 01easy

    Padding vs margin:

  2. 02medium

    You need a wrapping row of tags. Flexbox or grid?

  3. 03medium

    “Mobile-first” means…

04 Interview questions

browse all ↗

What gets asked on this topic — tap a card for how to approach it, the follow-ups, and the trap. Company tags are best-effort & sourced.

  • Commonly asked junior concept common When would you reach for flexbox vs CSS grid?

    Flexbox is for one-dimensional layout — a single row or column of items that flow and wrap (a toolbar, a row of tags, a navbar). Grid is for two-dimensional layout — rows and columns at once (a page's sidebar-plus-content, a gallery of cards). The rule of thumb: flex for a *line* of things, grid for a *layout* of regions. They compose, too — grid for the page skeleton, flex inside each region.

    What a strong answer covers
    • Flexbox = one axis (row or column) that can wrap.

    • Grid = two axes (rows and columns) for page structure.

    • Flex for a line of items; grid for a layout of regions.

    • Common pattern: grid for the page, flex inside each cell.

    Red flag Forcing a whole two-dimensional page layout out of nested flexboxes — grid expresses it directly and stays responsive.

    source: MDN — Introduction to CSS layout ↗