📦 Day 11: CSS Box Model Explained – Padding, Border, Margin in Simple Terms
👋 Introduction: Jab bhi aap kisi HTML element ko style karte ho – uska layout kaise dikhega yeh decide karta hai CSS Box Model.
- Box model kya hota hai?
- Padding, Border, Margin ka kya role hai?
- Real examples ke saath samajhne ki koshish karenge
📦 What is the CSS Box Model?
Har HTML element ek box ki tarah hota hai. Us box ke 4 layers hote hain:
|----------------------------| | Margin | | |----------------------| | | | Border | | | | |---------------| | | | | | Padding | | | | | | Content | | | | | |_______________| | | | |______________________| | |____________________________|
🧊 1. Content
Yeh actual element ka data hota hai – jaise text, image, etc.
<div>This is content</div>
📐 2. Padding
Padding content aur border ke beech ka space hota hai.
div {
padding: 20px;
}
🔹 Element ke andar space add hoti hai. Background color padding ke area tak dikhega.
🔲 3. Border
Element ke 4 sides par line banata hai.
div {
border: 2px solid black;
}
🔸 Border content + padding ke bahar lagta hai.
🧱 4. Margin
Margin element ke bahar ka space hota hai – doosre elements se gap create karta hai.
div {
margin: 30px;
}
🔹 Page me spacing maintain karne ke liye important hai.
🖼️ Example: Full Box Model in CSS
<style>
.box {
padding: 20px;
border: 2px solid blue;
margin: 30px;
background-color: lightyellow;
}
</style>
<div class="box">
Hello! This is a CSS Box Model example.
</div>
Hello! This is a CSS Box Model example.
🎯 Shorthand Properties
✅ Padding:
padding: 10px 20px 30px 40px;
/* top right bottom left */
✅ Margin:
margin: 20px auto;
/* top-bottom | left-right (auto center) */
🧠 Pro Tips:
Padding = inside spacing
Margin = outside spacing
Use
Padding = inside spacing
Margin = outside spacing
Use
box-sizing: border-box; to include padding and border inside total width.
* {
box-sizing: border-box;
}
🏁 Conclusion
- CSS Box Model ke 4 layers samjhe
- Real CSS code ke examples dekhe
- Padding, border, margin ka use seekha
Banaiye ek simple card UI jisme padding, margin aur border use ho – aur khud dekhiye box model in action!
Comments
Post a Comment