Box Model: Margin, Padding, Border
Solution idea
This task is about showing the four box layers in action: content, padding, border, and margin. A strong solution sets explicit padding for internal spacing, a visible border for boundaries, and margin to space cards apart, making it obvious how each layer affects layout and sizing.
Solution
Overview
This task is about showing the four box layers in action: content, padding, border, and margin. A strong solution sets explicit padding for internal spacing, a visible border for boundaries, and margin to space cards apart, making it obvious how each layer affects layout and sizing.
Approach — Apply Padding, Border, and Margin
Give each .card a fixed or max width, a padding value (e.g. 16px), a subtle border (e.g. 1px solid #ccc), and a margin to separate adjacent cards. Add a small border-radius for readability. The goal is visual clarity: you should be able to point at the padding, border, and margin in the rendered result.
<div class='card'>
Card 1
</div>
<div class='card'>
Card 2
</div>
<div class='card'>
Card 3
</div>.card {
padding: 16px;
border: 1px solid #ccc;
border-radius: 8px;
margin-bottom: 12px;
background: #fff;
}Notes & Pitfalls
Forgetting that padding affects box size unless box-sizing is set to border-box. Using only margin or padding for spacing makes it unclear which side creates the space.
Use padding for internal spacing, margin for separation between elements. Add a border to make box boundaries visible when debugging layout issues.
Resources
Similar questions
Guides
Preparing for interviews? Use Frontend Coding Challenges first, then move into a concrete Study Plan before targeted Company Prep.
Built in public
The code behind FrontendAtlas lives on GitHub. A star helps other frontend engineers find it.