CSS Full Course Day 15 [Hindi] π» | Pseudo-classes, Pseudo-elements & Variables! π | Mohit Decodes
π¨ CSS Tutorial β Day 15: Pseudo-classes, Pseudo-elements & Variables!
Welcome to Day 15 of the CSS Full Course [Hindi] by Mohit Decodes! Today, weβll explore powerful CSS features that help you style elements dynamically and efficiently β Pseudo-classes, Pseudo-elements, and CSS Variables.
πΉ Pseudo-classes
- Target elements in a specific state without adding extra classes
- Examples:
:hover
β when mouse is over an element:focus
β when element is focused:nth-child(n)
β target specific child elements
css
CopyEdit
a:hover {
color: #f44336;
}
li:nth-child(odd) {
background-color: #e0e0e0;
}
πΉ Pseudo-elements
- Style parts of an element like before or after content
- Common pseudo-elements:
::before
::after
css
CopyEdit
p::before {
content: "Note: ";
font-weight: bold;
color: #2196F3;
}
πΉ CSS Variables (Custom Properties)
- Define reusable values and keep code DRY (Donβt Repeat Yourself)
- Syntax:
css
CopyEdit
:root {
--main-color: #4caf50;
--padding: 10px;
}
.button {
background-color: var(--main-color);
padding: var(--padding);
}
π‘ Tips:
- Use pseudo-classes to add interactive styles easily
- Use pseudo-elements to add decorative content without extra HTML
- Use CSS variables for theme management and easy maintenance