#css
#tutorial
#beginner
Day 1: Selectors & Logic
Day 1: The Art of Selection
CSS (Cascading Style Sheets) is how we make HTML look good. The core concept of CSS is: Select something, then style it.
1. Basic Selectors
Element Selector
Targets all tags of a specific type.
p {
color: red; /* All paragraphs will be red */
}
Class Selector (.)
Targets elements with a specific class attribute. This is your workhorse.
<button class="btn-primary">Click Me</button>
.btn-primary {
background-color: blue;
color: white;
}
ID Selector (#)
Targets a unique element.
<div id="header-logo"></div>
#header-logo {
width: 200px;
}
2. The “Cascade” & Specificity
What happens if two rules conflict?
p { color: red; }
.text-blue { color: blue; }
If a paragraph has <p class="text-blue">, it will be BLUE.
Why? Because a Class is more specific than a Tag.
Hierarchy of Power:
!important(Avoid using this!)- Inline Styles (
style="...") - IDs (
#id) - Classes (
.class) - Elements (
div,p)
3. Combinators
Targeting elements based on relationships.
- Descendant (Space):
.card p(Anypinside.card) - Child (
>):.card > p(Direct child only) - Sibling (
+):h1 + p(Thepimmediately afterh1)
Homework for Day 1:
- Create an HTML file with 3 paragraphs.
- Give different classes to them (
.text-red,.text-bold, etc.). - Write CSS to style them selectively.
- Try to “break” specificy: Make a rule that overrides another.
Day 2: We paint with Colors & Gradients!