Perfect! Letβs roll into Lesson 9, where we make everything we’ve learned responsive β super important in todayβs mobile-first world.
π LESSON 9: Responsive Design & Media Queries
β Learning Goals:
- Understand what responsive design is
- Learn how to use media queries
- Make websites look good on all screen sizes
- Build a mobile-friendly layout with Flexbox + media queries
π§Ύ Lesson Content (Text for Website)
π± What is Responsive Design?
Responsive design means your website adapts to any screen size β whether it’s a phone, tablet, or desktop.
No more pinching and zooming. Everything fits just right!
π§© Why Is It Important?
- Over 60% of users browse on mobile
- Google ranks mobile-friendly sites higher
- Better user experience = more engagement
π§ Core Techniques
- β
Fluid Layouts: Use
%
,vw
,vh
, orflex
instead of fixedpx
widths - β
Flexible Images: Use
max-width: 100%
- β Media Queries: Apply different CSS rules for different screen sizes
π Basic Media Query Syntax
@media (max-width: 768px) {
body {
background-color: lightblue;
}
}
This changes the background only on screens smaller than 768px.
π§ͺ Responsive Card Layout
<style>
.container {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.card {
flex: 1;
min-width: 250px;
padding: 20px;
background: #fff3e0;
border: 1px solid #ffcc80;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
}
}
</style>
<div class="container">
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card">Card 3</div>
</div>
On desktop, the cards sit side-by-side.
On mobile, they stack vertically. Magic! π©β¨
π§ More Common Breakpoints
Device | Width (max) | Typical Media Query |
---|---|---|
Mobile | 480px | @media (max-width: 480px) |
Tablet | 768px | @media (max-width: 768px) |
Laptop | 1024px | @media (max-width: 1024px) |
Desktop | 1200px+ | @media (min-width: 1200px) |
π§ͺ Practice Task
β Create a simple page with:
- A 3-column layout on desktop
- A 2-column layout on tablets
- A 1-column layout on mobile
Use Flexbox + Media Queries to handle the layout switching.
π Quick Summary
- Responsive design adapts to all screen sizes
- Use flexible units, media queries, and wraps
- Design mobile-first, then enhance for larger screens
- Flexbox + media queries = modern responsive power!
π Next Lesson:
π Lesson 10: Project β Build a Responsive Landing Page
81
One Response