CSS Fundamentals and Layout
How the box model, cascade, flexbox, grid, positioning, responsive design, and units decide what a browser actually renders, and how to debug when they don't.
- Minutes to read
- 4
- Practice MCQs
- 25
- Interview Q&A
- 25
- Edition
- v2
- Editorial status
- Reviewed
- Relevant for
- Frontend EngineerProduct Engineer
Scope: CSS Living Standard, current to 2025. Baseline browser support as of Chrome 131, Firefox 133, Safari 18 (late 2024/early 2025)..
Curated: · Written: · Reviewed:
MCQ-2A design spec fixes each card's visible box at 280px wide, with 20px of horizontal padding and a 1px border on every side. The stylesheet sets `.card { width: 280px; padding: 0 20px; border: 1px solid #ccc; }` and a global reset applies `box-sizing: border-box` to every element. What are the card's content width and its rendered outer width?
Answer to see the discussion.
MCQ-1A design system ships a card declared as `.card { box-sizing: content-box; width: 200px; padding: 20px; border: 5px solid #333; }`, holding a block-level `.badge { width: 50%; padding: 10%; }` with no border, in normal flow. Measured in devtools, what are the card's and the badge's rendered widths?
Answer to see the discussion.
MCQ-3A nav link `<a class="nav-link" href="/pricing" aria-current="page">` matches exactly these five rules, in this order: `a:where(#cta, .nav-link) { color: red }`, `.nav-link[aria-current="page"] { color: green }`, `a.nav-link { color: orange }`, `:is(.nav-link, #cta) { color: blue }`, `[href="/pricing"] { color: purple }`. Nothing else sets `color` and none is `!important`. Which colour renders, and why?
Answer to see the discussion.
MCQ-5A design system ships `.card { color: #333; font-size: 18px; margin: 16px; border: 2px solid #ccc; }`, and each card contains `<div class="label">Total</div>` with no other author rules applying to it. In devtools, what are the label's computed `color`, `font-size`, `margin-top` and `border-top-width`?
Answer to see the discussion.
MCQ-15A page sets `html { font-size: 16px }` and nests three components: `.sidebar { font-size: 1.25rem }` contains `.widget { font-size: 1.5em }`, which contains `.label { font-size: 0.8em; padding-left: 0.5em }`. No other rule sets a font size or padding on these elements. Devtools reports the label's computed `font-size` and `padding-left`. Which pair is right?
Answer to see the discussion.
MCQ-13A stylesheet declares `.nav { padding: 24px; }`, then `@media (max-width: 768px) { .nav { padding: 8px; } }`, then `@media (min-width: 768px) { .nav { padding: 16px; } }`. QA sets the layout viewport to exactly 768px and reads the nav's computed padding in devtools. What does it report, and why?
Answer to see the discussion.
MCQ-16A mobile landing page's hero is declared `.hero { height: 100vh }`. On iOS Safari the page loads with the URL bar expanded; devtools reports the visible height as 745px with the bar expanded and 852px with it retracted, and the hero renders 852px tall, so the 'Start' button pinned to its bottom edge sits 107px below the fold until the user scrolls. The team needs the button visible on first paint and no reflow of the hero as the URL bar hides and shows. Which change meets both constraints?
Answer to see the discussion.
MCQ-4A page renders `<div id="main" class="card"><h2 class="title">x</h2></div>` under a stylesheet beginning `@layer reset, base, theme, components, utilities;` that then declares `@layer utilities{.card .title{color:orange}}`, `@layer components{#main .title{color:green}}`, `@layer base{#main .card .title{color:gray}}`, `@layer reset{.card .title{color:maroon}}`, `@layer theme{.title{color:purple}}`. Which color does the heading render?
Answer to see the discussion.
MCQ-25A design system ships BEM component CSS; product teams extend it with utilities. A heading is `<h2 class="card__title mt-4">`. `utilities.css` loads first with `.mt-4 { margin-top: 16px }`, then `components.css` with `.card .card__title { margin-top: 0 }`. Devtools reports `margin-top: 0px`. The team wants utilities to beat component styles on any element, without `!important` and without editing every component rule. Which change achieves that?
Answer to see the discussion.
MCQ-21A design system defines `:root { --motion: 500; }` and every toast declares `.toast { transition-duration: 250ms; transition-duration: var(--motion, 1s); }`. The toast renders inside `<div class="layer">`, whose own rule sets `.layer { transition-duration: 800ms; }`. `--motion` is not registered with `@property`, nothing else sets `transition-duration`, and no `!important` appears. What does devtools report as the toast's computed `transition-duration`, and why?
Answer to see the discussion.
MCQ-22A bilingual app renders the same card component in an English build under `<html dir="ltr">` and an Arabic build under `<html dir="rtl">`. The only rule setting its margins is `.card { margin-inline-start: 24px; margin-left: 4px; }`. Devtools reports the computed margins in each build. Which pair of readings is right?
Answer to see the discussion.
MCQ-18A notification stack is `<div class="stack"><div class="banner">…</div>…</div>`. `.stack` is a plain block with no padding, border or overflow set, and `.banner { margin: 24px 0; }`. The spec wants 48px between adjacent banners and 24px above the first and below the last, but devtools measures 24px between adjacent banners. Which single change produces the specified spacing?
Answer to see the discussion.
MCQ-20A `.layout` holds `.sidebar { float: left; width: 200px; height: 300px }` then `.content { border: 1px solid #ccc }`. Devtools shows `.content`'s border box starting at x=0, painting under the sidebar, while its text starts at x=200. Which single change starts `.content`'s border box at x=200 without hardcoding 200px and without clipping a tooltip overflowing its right edge?
Answer to see the discussion.
MCQ-6A toolbar is a flex row 500px wide with `flex-wrap: nowrap` and three children: `.brand { flex: 0 0 300px; }`, `.search { flex: 0 1 200px; }`, `.actions { flex: 0 2 300px; }`. All three have `min-width: 0`, no margins, and no borders or padding. The row's total flex base size is 800px, so it overflows by 300px. Measured in devtools, what are the three rendered widths?
Answer to see the discussion.
MCQ-7A 1000px-wide viewport renders `.shell { display: flex }` with `.sidebar { flex: 0 0 240px }` and `.main { flex: 1 }`; `.main` holds `.panel { display: flex }` whose only child `.token { white-space: nowrap; overflow: hidden }` contains a 900px-wide unbreakable string. Devtools reports `.main` at 900px and a document scrollWidth of 1140px, though the design wants `.main` to fill the remaining 760px. Which single change makes `.main` render at 760px?
Answer to see the discussion.
MCQ-8A product grid is declared as `.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }` inside a container whose content box is exactly 1200px wide. It holds three cards today, and a fourth card is appended to the markup. What does the grid render after the fourth card is added?
Answer to see the discussion.
MCQ-17A pricing page puts two paragraphs in a grid with `.grid { display: grid; grid-template-columns: min-content max-content; }` inside a 200px-wide content box. Column 1 holds `<p>Deploy now</p>`, column 2 `<p>Rollback the release now</p>`. A reset zeroes margins and padding, no gap, and every character including spaces renders at 8px. Measured in devtools, which account of the column widths and the grid's box is right?
Answer to see the discussion.
MCQ-9A dashboard tile is an inline-level grid declared as `.board { display: inline-grid; grid-template-columns: repeat(3, 100px); grid-auto-columns: 50px; gap: 10px; }` and holds two empty children, `.b { grid-column: 4 / 6; }` and `.c { grid-column: 2 / 5; }`. Nothing else sets a width, padding or border on the board or its children. Measured in devtools, what is the board's rendered width and what is `.c`'s rendered width?
Answer to see the discussion.
MCQ-10A card is `.page { position: relative }` > `.card { position: static; overflow: hidden; width: 240px; height: 120px }` > `<span class="badge">` with `.badge { position: absolute; top: -8px; right: -8px; width: 40px; height: 40px }`. The badge paints fully outside the card's top-right corner instead of being clipped. Why, and what single change makes the card clip it?
Answer to see the discussion.
MCQ-12A page renders a `.nav` bar and, below it, a `.main` flex container holding one `.card`; the card is pulled up with `margin-top: -40px` so it overlaps the nav's bottom edge. The stylesheet sets `.nav { position: relative; z-index: 5 }`, `.main { display: flex }` and `.card { z-index: 10; margin-top: -40px }`, and nothing else touches `position`, `z-index` or `display`. In the overlap region, which element paints on top, and why?
Answer to see the discussion.
MCQ-11A docs page lays out a sidebar and an article in a flex row: `.layout { display: flex }`, `.sidebar { position: sticky; top: 0 }`, `.article { height: 2400px }`. The sidebar holds 300px of links, the viewport is 800px tall, and devtools reports the sidebar's box as 2400px tall as it scrolls off the top with the article instead of sticking. Which change makes it stick?
Answer to see the discussion.
MCQ-14Markup: `<div class="shell"><aside class="sidebar"><article class="card">…</article></aside></div>`. CSS: `.shell { container: shell / inline-size; width: 1000px; }`, `.sidebar { container: side / inline-size; width: 300px; }`, `.card { width: 280px; }`, and `@container shell (min-width: 600px) { .card { display: grid; grid-template-columns: 1fr 1fr; } }`. What does `.card` render as?
Answer to see the discussion.
MCQ-19A filter panel is `.list { width: 320px; box-sizing: border-box; overflow-y: auto; }` with no padding or border, on a platform whose scrollbars are classic and 15px wide. With three items the list does not scroll; a filter that adds items makes it overflow. QA measures the inner content width before and after the filter, and the team wants that width to be the same in both states without a scrollbar track being painted while the list fits. Which change achieves that?
Answer to see the discussion.
MCQ-24A product carousel scrolls horizontally, and each card shows a star icon and the rating number, with the full phrase in `<span class="sr-only">4.5 out of 5 stars</span>`. The stylesheet ships `.sr-only { display: none }`, and screen reader users report the rating is never announced. The replacement rule must leave the card's layout unchanged and must not widen the carousel's scrollable area. Which replacement meets both constraints?
Answer to see the discussion.
MCQ-23A table renders 500 rows and a resize handler runs `rows.forEach((row) => { row.style.width = colWidth + 'px'; total += row.offsetHeight; })` on every drag frame. A Performance recording shows the handler taking 1,180 ms, with a Layout entry after every Recalculate Style, and deleting the `offsetHeight` read drops it to 9 ms. Which change removes that cost while keeping `total` correct?
Answer to see the discussion.