⬅ Back

🧱 CSS ELEMENT TYPES — FULL NOTES

🔹 1. display property

🧠 What does it do?

👉 Controls how an element behaves on the page

display: value;
✅ Main purpose
📌 Example
span {
  display: block;
}

👉 makes an inline element behave like a block

🔹 2. Types of elements

There are 3 main types:

🔹 3. Block elements

🧠 Characteristics
📊 Behavior
✔ You CAN use:
📌 Examples
<div></div>
<p></p>
<h1></h1>
<section></section>

🔹 4. Fixed width blocks

Even if width is set:

👉 blocks still stay one under another

💡 Important

Remaining space = margin-right: auto

🔹 5. Margin collapsing (IMPORTANT)

🧠 What happens?

Vertical margins DO NOT add up

👉 the bigger margin wins

📌 Example
.top {
  margin-bottom: 20px;
}

.bottom {
  margin-top: 40px;
}

👉 result = 40px, not 60px

🔹 6. Margin collapse rule

🔹 7. Margin collapsing (nested elements problem)

🧠 Problem

Child margin "escapes" parent

📌 Example
.inner {
  margin-top: 40px;
}

👉 pushes the parent instead

❗ Important rule

👉 Use margins between elements only

🔹 8. Horizontal centering

🧠 How to center a block?
.box {
  width: 300px;
  margin: 0 auto;
}
✔ Why it works

👉 auto margins split free space equally

🔹 9. Viewport

🧠 What is it?

👉 visible part of the page

💡 Important

🔹 10. Container (wrapper)

🧠 What is it?

👉 block that centers content

📌 Example
.container {
  width: 480px;
  margin: 0 auto;
  padding: 0 15px;
}
✔ Purpose

🔹 11. <div> element

🧠 What is it?

👉 universal container

✔ Characteristics
📌 Example
<div class="container"></div>

🔹 12. Inline elements

🧠 Characteristics
❗ Limitations
✔ Only works
📌 Example
a {
  padding-left: 20px;
  margin-right: 20px;
}
❌ Not working
a {
  width: 100px;
  margin-top: 20px;
}

🔹 13. Inline vertical padding issue

🧠 Problem

Vertical padding is visible BUT:

👉 does NOT affect layout

👉 overlaps other elements

❗ Conclusion

👉 avoid vertical spacing on inline elements

🔹 14. Fix: make inline → block

a {
  display: block;
}

🔹 15. Inline-block elements

🧠 Hybrid type

👉 combines block + inline

✔ Characteristics
📌 Example
.link {
  display: inline-block;
  padding: 16px 32px;
}
✔ Use cases

🔹 16. Inline spacing issue

🧠 Problem

Inline elements have small gaps

📏 Why?

👉 caused by font-size

📊 Rule

Gap ≈ 1/4 of font-size

📌 Example
body {
  font-size: 32px;
}

👉 gap = 8px

🔹 17. Hiding elements

🧠 How?
display: none;
✔ Effect
❗ Important

👉 cannot animate display

🔹 18. Example (tabs)

.pane {
  display: none;
}

.pane.active {
  display: block;
}

🔥 FINAL SUMMARY

🧠 Remember:

👉 block = structure

👉 inline = text

👉 inline-block = flexible

💪 Most important rules:

⬅ Back