CSS3 Course in Roman Hindi/Urdu - Beginner se Advanced Tak | Lecture 10: CSS3 Media Queries & Responsive Design Full Guide (Yaar, Breakpoints, Viewport Units, Mobile-First Approach – Full Deep Dive Se Samajh Aayega!)
Assalam-o-Alaikum yaar! Kya haal hai, dost? Pichli lecture mein typography seekh liya – fonts fancy, text effects glow, responsive sizes se content pop kar diya! Ab real-world hero: CSS3 Media Queries & Responsive Design! Yeh CSS3 ka must-tool hai sites ko mobile/tablet/desktop sab par perfect fit karne ke liye – breakpoints set, viewport units (vw/vh), mobile-first strategy se start. Hum is lecture mein media queries (@media rules), breakpoints (common sizes), viewport meta/units, aur mobile-first approach ko full detail mein bataayenge – har ek ka use kya, kyun zaroori, kahan lagana, aur real examples ke saath, jaise tere saath phone/computer switch kar ke test kar raha hoon. Tension mat le, step-by-step, code copy-paste se try karenge. Yeh seekh le toh sites ko universal banaayega – Google mobile-first index mein rank #1!
Yaar, responsive 2010 se trend, lekin CSS3 media queries ne easy bana diya – aaj 60%+ traffic mobile. Ready? Chal shuru!
CSS3 Media Queries & Responsive Design Kya Hai? (Yaar, Overview – Kyun Aur Kab Use Karein)
Dost, Media Queries CSS rules hain jo screen size/orientation par conditional styles apply karte (@media screen and (max-width: 600px) { ... }). Responsive Design sites ko flexible banaata – content adapt. Use: Layout adjust (desktop grid, mobile stack). Why: User experience (no zoom/pinch), SEO (mobile-friendly). Where: CSS file end mein. Example: @media (min-width: 768px) { .navbar { display: flex; } } – tablet par flex nav. Mobile-first: Small screen styles first, larger add. Viewport units (vw = 1% width) fluid sizing. Without: Fixed sites mobile mein break.
Fun fact: Ethan Marcotte ne 2010 mein coining kiya, CSS3 ne tools diye. Chalo components deep dive!
CSS3 Media Queries Syntax - Full Breakdown (Use, Why, Where with Examples)
Yaar, syntax @media (feature: value) { rules }; – full details: use kya, kyun, kahan, example.
- @media Screen: Use: Screen devices (not print). Why: Responsive only. Where: All queries. Example: @media screen and (max-width: 600px) { body { font-size: 14px; } } – mobile small text. Why: Print separate.
@media screen and (max-width: 600px) { body { font-size: 14px; } } - min-width/max-width: Use: Breakpoints set. Why: Size-based. Where: Layouts. Example: @media (min-width: 768px) { .container { width: 80%; } }
@media (min-width: 768px) { .container { width: 80%; } }Desktop Wide– tablet+ wide. Common: 320px mobile, 768 tablet, 1024 desktop. Why: Device ranges. - min-height/max-height: Use: Vertical space. Why: Tall/short screens. Where: Full-height. Example: @media (min-height: 800px) { .hero { height: 100vh; } } – tall screens full viewport. Use: Portrait/landscape.
@media (min-height: 800px) { .hero { height: 100vh; } } - orientation: Use: Portrait/landscape detect. Why: Rotate adjust. Where: Mobile. Example: @media (orientation: portrait) { .menu { flex-direction: column; } } – portrait stack. Why: Sideways fix.
@media (orientation: portrait) { .menu { flex-direction: column; } } - resolution: Use: DPI (high-res). Why: Retina images. Where: @media print. Example: @media (min-resolution: 2dppx) { img { image-rendering: crisp-edges; } } – high DPI sharp. Use: 4K screens.
@media (min-resolution: 2dppx) { img { image-rendering: crisp-edges; } }
Nesting Queries: @media (min-width: 600px) and (max-width: 900px) { ... } range. Yaar Tip: Mobile-first: Base styles small, min-width add larger. Not (max-width: 600px) invert.
Viewport Units & Meta - Responsive Foundation (Full with Examples)
Dost, viewport units screen relative – meta tag must.
- Viewport Meta: Use: Mobile zoom control. Why: Responsive base. Where: . Example: – width device, no zoom. Without: Desktop site mobile mein pinch. Values: user-scalable=no (avoid).
<meta name="viewport" content="width=device-width, initial-scale=1.0"> - vw (Viewport Width): Use: 1% screen width. Why: Fluid. Where: Headings. Example: font-size: 5vw;
font-size: 5vw;5% Width Text
– resize scale. Clamp with: clamp(1rem, 5vw, 3rem). - vh (Viewport Height): Use: 1% height. Why: Full screen. Where: Hero. Example: height: 100vh;
height: 100vh;Full Height– screen tall. - vmin/vmax: Use: Smaller/larger dimension %. Why: Square fit. Where: Icons. Example: width: 10vmin; Responsive square.
width: 10vmin;
Yaar Tip: Vw mobile headings ke liye, vh sticky footers. Clamp prevent too small/large.
Mobile-First Approach - Strategy Full (Why, How with Examples)
Yaar, mobile-first base small screen styles, larger add – fast load.
Use: Progressive enhancement. Why: 60% mobile first. Where: CSS cascade. Example: Base: .navbar { display: block; } @media (min-width: 768px) { .navbar { display: flex; } }
/* Base Mobile */
.navbar { display: block; }
/* Desktop Add */
@media (min-width: 768px) {
.navbar { display: flex; }
}Common Breakpoints: 480px phone, 768 tablet, 1024 desktop, 1440 large. Fluid: rem + vw mix.
Yaar Tip: Min-width queries use – base mobile, add desktop. Test: Chrome device emulation.
Apna Pehla Responsive Project (Yaar, Hands-On – Step-by-Step with Fixes)
Dost, ab banao responsive card layout!
Step 1: Setup
Folder "Responsive-Project". Files: index.html, resp.css. Live Server.
Step 2: Code Likh (Full with Why)
resp.css:
/* Viewport Meta in HTML */
body {
font-size: 16px; /* Base for rem */
line-height: 1.5;
}
/* Mobile-First Base */
.card-grid {
display: grid;
grid-template-columns: 1fr; /* Single column mobile */
gap: 15px;
padding: 10px;
}
.card {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
font-size: clamp(0.9rem, 2.5vw, 1.1rem); /* Responsive text */
}
h2 {
font-size: clamp(1.5rem, 5vw, 2.5rem);
text-align: center;
}
/* Tablet */
@media (min-width: 600px) {
.card-grid {
grid-template-columns: repeat(2, 1fr); /* 2 columns */
gap: 20px;
}
}
/* Desktop */
@media (min-width: 1024px) {
.card-grid {
grid-template-columns: repeat(3, 1fr); /* 3 columns */
max-width: 1200px;
margin: 0 auto;
}
.card {
height: 200px; /* Fixed height desktop */
display: flex;
align-items: center;
}
}
/* Landscape */
@media (orientation: landscape) and (max-height: 500px) {
body { font-size: 14px; } /* Small height adjust */
}
/* High DPI */
@media (min-resolution: 2dppx) {
.card { border: 0.5px solid #ddd; } /* Thinner borders */
}
/* Print */
@media print {
body { font-size: 12pt; color: black; }
.card { box-shadow: none; break-inside: avoid; }
}
index.html:
<!DOCTYPE html>
<html lang="hi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Viewport -->
<title>Responsive Demo - Lecture 10</title>
<link rel="stylesheet" href="resp.css">
</head>
<body>
<h2>Responsive Card Grid</h2>
<div class="card-grid">
<div class="card"><h3>Card 1</h3><p>Mobile single, tablet 2, desktop 3 columns.</p></div>
<div class="card"><h3>Card 2</h3><p>Clamp sizes fluid text.</p></div>
<div class="card"><h3>Card 3</h3><p>Viewport vw for responsive.</p></div>
<div class="card"><h3>Card 4</h3><p>Extra for wrap test.</p></div>
</div>
</body>
</html>
Yaar, Yeh Kaise Kaam Karta? Base 1 column mobile, min-width add columns, clamp fluid font, viewport meta zoom prevent. Test: Resize – columns change, text scales. Mistakes: Viewport miss? Mobile zoom. Breakpoint galat? Device test.
Step 3: Test aur Tweak (Dost Help)
1. Save, refresh – resize columns? 2. Inspect: Responsive tab emulate devices. 3. Tweak: vmin card size add square. Landscape query test rotate phone. Issue: No change? Media end CSS mein rakh.
Practice Tasks (Yaar, Challenges – Level Up Kar)
- Easy (10 Min): Code copy, max-width: 400px query add font-size small, test. (Use: Narrow screens.)
- Medium (15 Min): Orientation landscape mein grid column 4 banao.
- Advanced (20 Min): Mobile-first navbar: Base block, min-width flex.
Dost Challenge: Ek full responsive page banao breakpoints se (phone stack, desktop grid), viewport units headings. Screenshot!
Common Questions (Yaar, Sab Clear – FAQ Dost Style)
- Q1: Mobile-first vs desktop-first?
- A: Mobile-first base small, add larger (fast load). Desktop old way max-width.
- Q2: Breakpoints kitne common?
- A: 600 mobile, 768 tablet, 1024 desktop – design se adjust.
- Q3: Vw vs % difference?
- A: Vw viewport (screen), % parent. Vw fluid full screen.
- Q4: Media print ka use?
- A: PDF/print styles (no images, black text).
- Q5: Queries nesting?
- A: CSS nesting @media inside @media (experimental), or separate.
Next Lecture Teaser
Yaar, agla pro: CSS3 Variables & Custom Properties Full Guide – Themes, Calc, Responsive Themes. Responsive practice kar, variables easy lagega. Comment bata kaisa tha – saath hain!
Course Outline Hint: - L1: Basic Intro - L2: Advanced Selectors - L3: Box Model - L4: Flexbox - L5: Grid - L6: Animations - L7: Transforms - L8: Colors/Backgrounds - L9: Typography - L10: Responsive (Yeh) - ... L20: Projects.
Doubts ho toh bol, dost. Allah Hafiz! Responsive master kar le. 😊

