π’ LESSON 3 PRACTICAL
π’ LESSON 3 PRACTICAL β Box Model (Spacing Like a Pro)
π― Goal
You will understand:
- margin (outside space)
- padding (inside space)
- border
- How to control layout cleanly
FIRST: Understand This (CRITICAL)
Every element is a box:
[ margin ]
[ border ]
[ padding ]
[ content ]
π Most beginners mess up here β this is why layouts look bad.
π§βπ» STEP 1: Update Your CSS
Modify your .card:
.card {
background: white;
width: 320px;
padding: 30px; /* inside space */
margin: 100px auto; /* outside space */
border: 3px solid #4facfe;
border-radius: 10px;
text-align: center;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}π STEP 2: See the Difference
Try changing:
1. Padding
padding: 50px;π Content moves away from border
Margin
margin: 200px auto;π Card moves away from screen edges
3. Border
border: 5px dashed red;π You visually see the box clearly
π§ͺ STEP 3: Add More Elements
Update your HTML:
<div class="card">
<h1>Welcome to CSS</h1>
<p>This is my first styled card.</p>
<button>Learn More</button>
</div>
<div class="card">
<h1>Second Card</h1>
<p>Practicing spacing is important!</p>
<button>Click Me</button>
</div>π― STEP 4: Add Space Between Cards
.card {
margin: 50px auto;
}π Now cards donβt stick together
π₯ STEP 5: Pro Trick (VERY IMPORTANT)
Add this at the top of your CSS:
* {
box-sizing: border-box;
}π This makes sizing predictable like a pro
π― CHALLENGE (DO THIS)
Make your design better:
- Add space between:
- Title and paragraph
- Paragraph and button
π Hint:
h1 {
margin-bottom: 10px;
}
p {
margin-bottom: 20px;
}π‘ REAL DEV INSIGHT
padding= comfort inside π¦margin= space outside πborder= visual boundary π²
π Master this = clean UI always

1 Response
[…] Next Lesson […]