โ๏ธ CSS COURSE โ MODULE 14: ADVANCED CSS
๐ File: advanced.md
โ๏ธ Advanced CSS Techniques
๐ Introduction
Advanced CSS is about:
- precise control
- smart selectors
- better structure
- avoiding common mistakes
๐ This is what separates beginners from professionals.
๐ฏ 1. Pseudo-Classes
Pseudo-classes define states of elements.
๐ฑ๏ธ Hover
button:hover {
background: blue;
}
โ When mouse is over element
โจ๏ธ Focus
input:focus {
border: 2px solid blue;
}
โ When input is selected
๐ First Child
p:first-child {
color: red;
}
โ First element only
๐ Last Child
p:last-child {
color: green;
}
๐ง 2. Pseudo-Elements
Used to style parts of elements
โจ Before
h1::before {
content: "๐ฅ ";
}
โจ After
h1::after {
content: " โ";
}
โ Adds content without HTML
๐งฉ First Letter
p::first-letter {
font-size: 30px;
}
๐ฏ 3. Specificity (VERY IMPORTANT)
CSS priority system:
inline > id > class > element
Example:
p {
color: blue;
}
.text {
color: red;
}
#id {
color: green;
}
โ ID wins always
โ ๏ธ 4. !important (USE CAREFULLY)
p {
color: red !important;
}
โ Overrides everything โ ๏ธ Should be avoided in real projects
๐ง 5. CSS Inheritance
body {
color: blue;
}
โ Children inherit styles automatically
๐ 6. Combinators Review
div p {
}
div > p {
}
h1 + p {
}
โ Control relationships between elements
๐งฉ Real Example
<div class="card">
<h1>Hello CSS</h1>
<p>Advanced styling</p>
<input type="text" placeholder="Type here" />
</div>
.card {
padding: 20px;
}
.card h1::before {
content: "๐ ";
}
.card p {
color: gray;
}
.card input:focus {
border: 2px solid blue;
}
โ ๏ธ Common Mistakes
- Overusing
!importantโ - Not understanding specificity โ
- Wrong pseudo-element usage โ
- Overcomplicated selectors โ
๐ฏ Pro Rules
โ Keep CSS simple โ Avoid deep nesting โ Prefer classes over IDs โ Use pseudo-elements for UI effects
๐งช Mini Exercise
Create:
- Button with hover effect
- Input with focus style
- Heading with icon using
::before - Paragraph with first-letter styling
- Card using multiple pseudo-classes