PHASE 1: CSS FOUNDATIONS
PHASE 2: SELECTORS & SPECIFICITY
PHASE 3: BOX MODEL
PHASE 4: DISPLAY & POSITIONING
PHASE 5: FLEXBOX
PHASE 6: CSS GRID
PHASE 7: RESPONSIVE DESIGN
PHASE 8: CSS IN REAL WORLD
(Where styling power begins)
CSS = Cascading Style Sheets
It controls:
If HTML is skeleton → CSS is skin + clothes + design.
Imagine HTML without CSS:
CSS makes websites look professional.
There are 3 ways.
🔹 Inline CSS (Not Recommended)
<p style="color:red;">Hello</p>
Bad practice for large projects.
🔹 Internal CSS
<style>
p {
color: red;
}
</style>Used inside <head>.
🔹 External CSS (Professional Way)
<link rel="stylesheet" href="style.css">
Then in style.css:
p {
color: red;
}✔ Clean ✔ Scalable ✔ Industry standard
selector {
property: value;
}Example:
p {
color: blue;
}Breakdown:
💡 Engineering analogy:
🔹 Color
color: red;
🔹 Background Color
background-color: yellow;
🔹 Font Size
font-size: 20px;
🔹 Text Align
text-align: center;
🔹 Width & Height
width: 300px;
height: 200px;🔹 px (Pixels)
Fixed size.
width: 300px;
🔹 % (Percentage)
Relative to parent.
width: 50%;
🔹 em & rem (Responsive Units)
Professional developers prefer rem.
Why is it called Cascading Style Sheets?
Because:
Example:
p {
color: blue;
}
p {
color: red;
}Final color → red (Because last one overrides)
/* This is a comment */
(This is where CSS becomes powerful)
p {
color: blue;
}Targets all <p> tags.
HTML:
<p class="highlight">Hello</p>
CSS:
.highlight {
color: red;
}Class uses .
HTML:
<p id="main">Hello</p>
CSS:
#main {
color: green;
}ID uses #
🚨 Rule:
ID should be unique per page.
h1, h2, p {
color: blue;
}div p {
color: red;
}Targets <p> inside <div>.
div > p {
color: blue;
}Only direct children.
a:hover {
color: red;
}Used for:
Priority order:
Inline > ID > Class > Element
Example:
#id { color: red; }
.class { color: blue; }
p { color: green; }ID wins.
Everything in CSS is a box.
Every element has:
| Margin |
| Border |
| Padding |
| Content |Actual text or image.
Space inside border.
padding: 20px;
border: 2px solid black;
Space outside element.
margin: 10px;
Total width = Content + Padding + Border
Margin is outside.
Default:
box-sizing: content-box;
Better:
box-sizing: border-box;
Why?
Because width includes padding & border.
Professional developers always use:
* {
box-sizing: border-box;
}(This is where layout control begins)
Every HTML element has a default display value.
🔹 Block Elements
Examples:
They:
🔹 Inline Elements
Examples:
They:
🔹 Inline-Block
display: inline-block;
Behaves like:
Used a LOT in layout.
🔹 None
display: none;
Element disappears completely.
(Not hidden. Removed from layout.)
This controls element placement.
There are 5 types.
🔹 static (default)
Normal document flow.
🔹 relative
position: relative;
top: 20px;Moves relative to its original position.
Does NOT remove it from flow.
🔹 absolute
position: absolute;
top: 0;
left: 0;Removed from normal flow.
Positioned relative to nearest positioned ancestor.
If no ancestor → relative to page.
🔹 fixed
position: fixed;
top: 0;Fixed to screen.
Used for:
🔹 sticky
position: sticky;
top: 0;Behaves like relative until scroll reaches threshold.
Then becomes fixed.
Used in:
💡 Engineering Analogy
Flexbox changed CSS forever.
Before flexbox: Layout = pain.
After flexbox: Layout = easy.
Used for:
.container {
display: flex;
}Now children become flex items.
flex-direction: row;
flex-direction: column;Row = horizontal
Column = vertical
If direction = row:
Controls horizontal alignment.
justify-content: center;
justify-content: space-between;
justify-content: space-around;Controls vertical alignment.
align-items: center;
align-items: flex-start;
align-items: flex-end;display: flex;
justify-content: center;
align-items: center;This perfectly centers content.
Interview favorite.
flex-wrap: wrap;
Allows items to move to next line.
Important for responsiveness.
Flexbox = 1D layout
Grid = 2D layout
Grid handles rows + columns together.
.container {
display: grid;
}grid-template-columns: 1fr 1fr 1fr;
Creates 3 equal columns.
grid-template-rows: 100px 200px;
gap: 20px;
Adds spacing between grid items.
grid-template-areas:
"header header"
"sidebar content"
"footer footer";Professional layout control.
Modern websites must work on:
Website adapts to screen size.
@media (max-width: 768px) {
body {
background: red;
}
}Applies style when screen is small.
Write mobile styles first.
Then expand for desktop.
Professional method.
Use:
Instead of fixed px.
Don't overuse IDs.
Use clean names:
.card
.navbar
.button-primaryRemove default browser styles:
* {
margin: 0;
padding: 0;
}Avoid: