Practice Exercise
Create three boxes with different widths, padding, borders and margins. Calculate their border-box widths manually, then use browser DevTools to verify the calculations.
Quiz — 10 MCQs
- Which four areas make up the traditional box model? (A) Content, padding, border, margin (B) Header, footer, body, title (C) Grid, flex, float, clear (D) Width, height, color, font. Answer: A. These are the four box-model areas.
- Which area sits directly around the content? (A) Margin (B) Padding (C) Outline (D) Position. Answer: B. Padding lies between content and border.
- Which area is outside the border? (A) Content (B) Padding (C) Margin (D) Line height. Answer: C. Margin separates the box from neighboring content.
- What is the default box-sizing value for ordinary elements? (A) border-box (B) content-box (C) margin-box (D) padding-box. Answer: B. The default is content-box.
- With content-box, what is the border-box width for width 200px, horizontal padding 20px per side and 5px borders per side? (A) 200px (B) 230px (C) 250px (D) 290px. Answer: C. 200 + 40 + 10 = 250px.
- What does border-box include in its declared width? (A) Content, padding and border (B) Margin only (C) Margin and outline only (D) Content only. Answer: A. Margins remain outside the border box.
- Which shorthand sets top and bottom to 10px and left and right to 20px? (A) padding: 10px 20px (B) padding: 20px 10px (C) padding: 10px (D) padding: 10px 20px 30px. Answer: A. Two-value shorthand means vertical then horizontal.
- Can vertical margins collapse in some block layouts? (A) Yes (B) Never (C) Only on images (D) Only with Grid. Answer: A. Adjacent block margins can collapse under specific conditions.
- Do margins count inside a border-box width? (A) Yes (B) No (C) Only when colored (D) Always on mobile. Answer: B. Margins lie outside the border box.
- Which tool helps inspect an element's box model? (A) Browser DevTools (B) A database editor (C) Git log only (D) Email client. Answer: A. DevTools displays dimensions, padding, borders and margins.
Key Takeaways
- Understand the four box-model areas.
- Use border-box for predictable component sizing.
- Know the shorthand order and when vertical margins collapse.