Write CSS that looks great on every screen — from a 320px phone to a 4K monitor — without rewriting your styles from scratch.
What You'll Learn
This lecture takes your CSS skills to the next level with the techniques used in every professional web project:
🎨 CSS Variables — define your colors and spacing once in :root, use them everywhere
📐 Responsive Units — rem, vw, vh, and the powerful clamp() function for fluid sizing
📲 Media Queries (Mobile-First) — write styles for mobile by default, then scale up with min-width
✨ CSS Transitions & Transforms — smooth hover effects with translateY, scale, and opacity
🖼️ Responsive Images — object-fit: cover and zoom-on-hover with overflow: hidden
📌 Sticky Navigation — keep your navbar in view as the user scrolls
🌑 Overlay Effects — darken hero backgrounds with the ::before pseudo-element
Why This Matters
A layout that only works on one screen size isn't production-ready. After this lecture, your projects will adapt intelligently to any device — and your hover effects and transitions will feel polished and intentional, not like an afterthought.
Before You Watch
Make sure you've completed Lecture 4: Flexbox & CSS Grid — this lecture builds directly on those layout skills.
You should be comfortable with:
Building layouts with Flexbox and Grid
Basic CSS selectors and the box model
📎 The cheatsheet for this lecture is attached below the video. The responsive units reference table and media query breakpoints are especially worth bookmarking!
Advanced CSS & Responsive Design Cheatsheet
Quick reference for all responsive design concepts covered in Lecture 5.
CSS Custom Properties (Variables)
Define once in :root, use everywhere with var().
1/* Declare variables */
2:root{
3--color-primary:#C9A84C;
4--space-md:1.5rem;
5--text-xl:clamp(1.5rem,4vw,2rem);
6}
7
8/* Use variables */
9h1{
10color:var(--color-primary);
11margin-bottom:var(--space-md);
12font-size:var(--text-xl);
13}
14
15/* With fallback value */
16p{
17color:var(--color-primary,#FFD700);
18}
Concept
Syntax
Example
Declare
--name: value;
--color-bg: #0A0A0A;
Use
var(--name)
background: var(--color-bg);
Fallback
var(--name, fallback)
color: var(--color-bg, black);
Scope
:root { }
Available everywhere on the page
Pro Tip: Name variables by purpose, not value: --color-primary not --gold-color. If you rebrand, the name still makes sense.
Responsive Units
Unit
Relative To
Best For
Example
px
Nothing (absolute)
Borders, shadows
border: 1px solid;
rem
Root font size (16px default)
Font sizes, spacing, margins
padding: 1.5rem; (= 24px)
em
Parent font size
Nested scaling (rarely used)
margin: 0.5em;
vw
1% of viewport width
Full-width elements, fluid sizing
width: 50vw;
vh
1% of viewport height
Full-screen sections
min-height: 100vh;
%
Parent element
Fluid widths
width: 50%;
rem Quick Reference
rem
Pixels (at 16px base)
0.5rem
8px
1rem
16px
1.5rem
24px
2rem
32px
3rem
48px
4rem
64px
The clamp() Function
Fluid sizing: clamp(minimum, preferred, maximum)
1/* Font scales smoothly between 2rem and 3.5rem based on viewport */
2h1{
3font-size:clamp(2rem,6vw,3.5rem);
4}
5
6/* Padding scales with viewport */
7section{
8padding:clamp(1rem,4vw,3rem);
9}
How it works:
Minimum: Never go smaller than this (e.g., 2rem)
Preferred: Use this value (scales with viewport, e.g., 6vw)
Maximum: Never go bigger than this (e.g., 3.5rem)
Media Queries (Mobile-First)
Base CSS targets mobile. Use min-width to enhance for larger screens.