0
0
CSSmarkup~20 mins

Common box model issues in CSS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Box Model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Box Model Width Calculation
Given a div with width: 200px, padding: 20px, border: 5px solid, and box-sizing: content-box, what is the total rendered width of the box in the browser?
A250px
B200px
C250px plus padding and border
D250px plus margin if any
Attempts:
2 left
💡 Hint
Remember that with content-box, padding and border add to the width.
📝 Syntax
intermediate
2:00remaining
Fixing Unexpected Box Size Growth
Which CSS rule correctly prevents a div with width: 300px and padding: 30px from growing beyond 300px total width?
Apadding: 0;
Bbox-sizing: content-box;
Cwidth: calc(300px - 60px);
Dbox-sizing: border-box;
Attempts:
2 left
💡 Hint
Try to include padding inside the width instead of adding it outside.
rendering
advanced
2:00remaining
Visual Result of Mixed Box-Sizing
You have two sibling div elements inside a container of 500px width. The first div has width: 250px; padding: 20px; box-sizing: content-box;. The second div has width: 250px; padding: 20px; box-sizing: border-box;. What will you see visually?
ABoth divs fit side by side exactly inside the container.
BThe first div overflows the container, the second fits exactly.
CBoth divs overflow the container.
DThe second div overflows, the first fits exactly.
Attempts:
2 left
💡 Hint
Remember how padding affects total width differently for content-box and border-box.
selector
advanced
2:00remaining
Selecting Elements to Fix Box Model Issues
You want to apply box-sizing: border-box; to all elements and their pseudo-elements to avoid box model issues globally. Which CSS selector achieves this correctly?
A*, *::before, *::after { box-sizing: border-box; }
Bdiv, span, p { box-sizing: border-box; }
Chtml, body { box-sizing: border-box; }
D* { box-sizing: border-box; }
Attempts:
2 left
💡 Hint
Remember pseudo-elements can add extra boxes that affect layout.
accessibility
expert
3:00remaining
Ensuring Accessible Focus Styles with Box Model
You add a focus outline to buttons using outline: 3px solid blue;. However, the outline is clipped because the button has overflow: hidden; and padding. How can you fix this so the focus outline is fully visible and accessible?
AUse <code>outline-offset: 3px;</code> to move the outline inside.
BAdd <code>box-sizing: border-box;</code> to the button.
CWrap the button in a container with padding and apply outline to the container.
DRemove <code>overflow: hidden;</code> from the button.
Attempts:
2 left
💡 Hint
Think about how to keep the outline visible without changing button's overflow or box model.