🏠 Home / Hub

🎨 CSS Lesson 09 — Responsive Design

← Back to CSS Menu  |  🏠 Hub

1. Viewport Meta Tag — မဖြစ်မနေ ထည့်ရမယ်!

<!-- HTML <head> ထဲ ဒါ မပါရင် mobile မှာ zoom out ဖြစ်မယ် -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">

width=device-width  → screen width နဲ့ ညှိ
initial-scale=1.0   → zoom factor 100%
⚠️ Responsive site တိုင်းမှာ ဒါမပါရင် mobile မှာ လုံးဝ မကောင်းဘူး!

2. @media — Media Queries

/* Mobile First approach ✅ (recommended) */
/* base styles → mobile */
.container { grid-template-columns: 1fr; }

/* tablet and up */
@media (min-width: 768px) {
  .container { grid-template-columns: repeat(2, 1fr); }
}

/* desktop and up */
@media (min-width: 1024px) {
  .container { grid-template-columns: repeat(3, 1fr); }
}

/* ---- */
/* Desktop First approach */
.container { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 768px) {  /* max-width သုံး */
  .container { grid-template-columns: 1fr; }
}

Common Breakpoints:

📱 Mobile
< 480px
📱 Large Mobile
480–767px
📟 Tablet
768–1023px
💻 Desktop
1024px+
🖥 Wide
1280px+

3. Responsive Units

px   → absolute, fixed pixels
%    → relative to parent
em   → relative to element's font-size
rem  → relative to root font-size ✅
vw   → 1% of viewport width   (1vw = 1%)
vh   → 1% of viewport height
vmin → smaller of vw/vh
vmax → larger of vw/vh
UnitRelative toUse case
pxScreen pixels (fixed)Border, icons, fine details
%Parent elementFluid widths, images
remRoot html font-sizeFont sizes, spacing ✅
emCurrent font-sizePadding relative to text
vwViewport widthFull-width sections
vhViewport heightFull-height hero sections
width: 100% (parent ရဲ့ 100%)
width: 50%
width: 60vw (viewport ရဲ့ 60%)
font-size: 1rem (16px default)
font-size: 1.5rem (24px)
font-size: clamp(14px, 2.5vw, 20px) — fluid!

4. Responsive Images

img {
  max-width: 100%;  /* ✅ image က parent ကျော်မသွားဘဲ responsive */
  height: auto;     /* aspect ratio ထိန်း */
}

/* Object-fit */
img { object-fit: cover; }   /* crop to fill */
img { object-fit: contain; } /* fit inside, letterbox */
img { object-fit: fill; }    /* stretch to fill */

cover (crop)

image

contain (letterbox)

max-width: 100%

fluid image

5. Mobile First — Live Demo

Browser ကို resize လုပ်ကြည့် ဒါမဟုတ် Dev Tools F12 → mobile emulator သုံးပါ

⚡ Logo
Card 1

3 cols → 2 cols → 1 col

Card 2

Resize to see!

Card 3

Responsive grid

/* Mobile first */
.resp-cards { grid-template-columns: 1fr; }
@media (min-width: 601px) { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 1024px){ grid-template-columns: repeat(3, 1fr); }

6. Simulate Breakpoints

⚡ Brand
Card 1
Card 2
Card 3

Current: Desktop

← CSS 08  |  Next: CSS Lesson 10 → CSS Variables

📌 Study Checklist