ရိုးရိုးလေး ရှင်းပြမယ်
ရိုးရိုးလေး ရှင်းရရင်
ဒီ lesson မှာ အသစ် property တွေ သိပ်မသင်ပါဘူး။ Selector၊ box model၊ color၊ gradient၊ transition၊ responsive width၊ custom property တွေကို project သေးသေးလေး တစ်ခုထဲမှာ ပေါင်းသုံးကြည့်ပါမယ်။ Responsive profile card တစ်ခုပါ။ စတင်လေ့လာသူအတွက် လုံလောက်အောင် ရိုးရှင်းပေမယ့် website အစစ်တွေမှာလည်း တကယ် အသုံးဝင်ပါတယ်။
LEGO နဲ့ အိမ်ဆောက်သလိုပါပဲ။ အုတ်ခဲ တစ်လုံးချင်းစီ (property တစ်ခုချင်းစီ) ကို သိပြီးသားပါ။ အခု ခက်တာက ဘယ်အစဉ်နဲ့ ဆက်မလဲ၊ ပြီးတော့ ဆောက်ပြီးတဲ့ အိမ်ကို လှုပ်ကြည့်ရင် မပြိုဘူးလား ဆိုတာပါ။ ဒီ pattern ကို team member card၊ product card၊ creator profile၊ service card တွေအတွက် ပြန်သုံးနိုင်ပါတယ်။
Problem → Why → Solution
ပြဿနာ: screenshot နဲ့ ကိုက်ပေမယ့် user နဲ့ မကိုက်
Designer ပေးတဲ့ desktop screenshot နဲ့ pixel တိုင်း ကိုက်အောင် card ကို width: 360px၊ height: 420px နဲ့ ရေးလိုက်ပါတယ်။ Screenshot ထဲက နာမည်တိုတိုနဲ့ ပြီးပြည့်စုံ ပါတယ်။ ဒါပေမယ့် 320px phone မှာ card က screen ထက် ကျယ်နေပါတယ်။ "Aung Kyaw Thu Htet Naing (Senior Frontend Engineer)" လို နာမည်ရှည် ရောက်လာတော့ စာသားတွေ 420px box အောက်ကို လျှံထွက်သွားပါတယ်။
Button ရဲ့ focus outline ကိုလည်း "ရုပ်ဆိုးလို့" outline: none နဲ့ ဖျက်ထားပါတယ်။ Mouse မသုံးဘဲ Tab key နဲ့ သွားတဲ့ user က button ပေါ် ရောက်နေလား မသိရတော့ပါဘူး။ Screenshot တစ်ပုံက ဒီပြဿနာ သုံးခုလုံးကို မပြနိုင်ပါဘူး။
.profile-card {
width: 360px; /* wider than a 320px phone */
height: 420px; /* long names spill out */
padding: 24px;
}
.profile-button:focus {
outline: none; /* keyboard users lose their place */
}"ပြီးပြီ" ဆိုတာ ဘာကို ဆိုလိုတာလဲ
Screenshot က content တစ်မျိုး၊ screen width တစ်ခု၊ mouse user တစ်ယောက်ကိုပဲ ပြပါတယ်။ Component တစ်ခု ပြီးပြီလို့ ပြောဖို့ content ပြောင်းလဲမှု၊ screen width အမျိုးမျိုး၊ input နည်းလမ်း အမျိုးမျိုးမှာ အလုပ်လုပ်ရပါမယ်။ ဒါကြောင့် ကန့်သတ်ချက် (min()၊ min-height) နဲ့ state (focus-visible) တွေကို စကတည်းက ထည့်စဉ်းစားရပါတယ်။
Core concept: mini project ကို အဆင့်လိုက် ဆောက်နည်း
Project သေးသေးလေး ဖြစ်ပေမယ့် အစဉ်မှန်နဲ့ ဆောက်ရင် နောက်ပိုင်း ပြန်ပြင်စရာ နည်းပါတယ်။ Professional developer တွေလည်း component တိုင်းအတွက် ဒီအဆင့်ငါးဆင့်ကို အတိုချုပ် လုပ်လေ့ရှိပါတယ်။
၁။ Content နဲ့ HTML ကို အရင်ရေးပါ
Card တစ်ခုက သီးခြား content တစ်ခုဖြစ်လို့ <article> ကို သုံးပါတယ်။ နာမည်က <h2>၊ ဖော်ပြချက်က <p>၊ နေရာတစ်ခုဆီ သွားတာမို့ link က <a> ပါ။ Style မပါဘဲ ဖတ်ကြည့်ရင်တောင် အဓိပ္ပာယ် ရှိရပါမယ်။ Avatar အက္ခရာတွေကတော့ အလှသက်သက်မို့ aria-hidden="true" နဲ့ screen reader ကနေ ဖျောက်ထားပါတယ်။
၂။ Design token တွေကို စုစည်းပါ
Card ထဲမှာ ထပ်ခါထပ်ခါ ပေါ်တဲ့ အရောင်နဲ့ radius တွေကို :root ထဲမှာ --accent၊ --radius လို custom property အဖြစ် ထားပါ။ နောက်ပိုင်း theme ပြောင်းချင်ရင် တစ်နေရာတည်းမှာ ပြင်ရုံပါပဲ။
၃။ Component ကို ကန့်သတ်ချက်နဲ့ style လုပ်ပါ
width: 360px အစား width: min(100%, 360px) ကို သုံးပါ။ Height ကို လုံးဝ မပေးဘဲ content ကို box အမြင့်ကို ဆုံးဖြတ်ခိုင်းပါ။ နာမည်ရှည်တွေအတွက် h2 မှာ overflow-wrap: anywhere ထည့်ပါ။
၄။ State တွေ ထည့်ပါ
Mouse အတွက် :hover၊ keyboard အတွက် :focus-visible နဲ့ animation လျှော့ချင်သူအတွက် prefers-reduced-motion ကို ထည့်ပါ။ :focus-visible က keyboard နဲ့ ရောက်လာတဲ့အခါမှ outline ကို ပြလို့ mouse click တိုင်းမှာ outline မပေါ်ပါဘူး။
၅။ Stress test လုပ်ပါ
320px width၊ နာမည်ရှည်၊ browser zoom 200%၊ Tab key တစ်ခုချင်း၊ system ရဲ့ reduced motion setting နဲ့ စမ်းပါ။ တစ်ခုခု ပျက်ရင် အဆင့် ၃ ဒါမှမဟုတ် ၄ ကို ပြန်သွားပါ။
အစဉ်က ဘာကြောင့် အရေးကြီးလဲ
HTML ကို style နဲ့ ရောပြီး ရေးရင် "ဒီ div က ဘာလဲ" ဆိုတာ မေ့သွားတတ်ပါတယ်။ Token မရှိဘဲ component ရေးရင် အရောင်တွေ ပြန့်ကျဲပါတယ်။ State တွေကို နောက်ဆုံးမှ ထည့်ရင် outline နဲ့ transition တွေ layout ကို မထိခိုက်ဘူးလား ချက်ချင်း မြင်ရပါတယ်။
- Content နဲ့ semantic HTML
- Token တွေကို :root ထဲ စု
- ကန့်သတ်ချက်နဲ့ component style
- Hover၊ focus၊ motion state ထည့်
- 320px၊ စာရှည်၊ Tab နဲ့ စမ်း
အဆင့် ၅ မှာ ပျက်တာ တွေ့တိုင်း ဒါက အရှုံး မဟုတ်ပါဘူး။ User မတွေ့ခင် ကိုယ်တိုင် အရင်တွေ့တာပါ။
အခြေခံ ပုံစံ
:root { --token-name: value; }
.component {
width: min(100%, var(--max-width));
color: var(--token-name);
}
.component__action:hover { /* mouse feedback */ }
.component__action:focus-visible { outline: 3px solid var(--token-name); }
@media (prefers-reduced-motion: reduce) { /* remove motion */ }Token တွေကို အပေါ်ဆုံးမှာ သတ်မှတ်၊ component က token တွေကို var() နဲ့ ပြန်သုံးပြီး fluid width ရှိပါတယ်။ Interactive element တိုင်းမှာ hover နဲ့ focus-visible state ရှိပြီး motion ကို user setting နဲ့ ပိတ်လို့ရပါတယ်။
Responsive profile card
ဒီ card ကို token တွေ၊ focus state နဲ့ reduced motion သုံးပြီး တည်ဆောက်ထားပါတယ်။ ပုံ file မလိုအောင် avatar ကို အက္ခရာ "TL" ပါတဲ့ စက်ဝိုင်းနဲ့ အစားထိုးထားပါတယ်။ ပုံအစစ် ထည့်ချင်ရင် <img> ကို width/height 96px နဲ့ object-fit: cover ပေးပါ။ ပုံရဲ့ အချိုး မတူရင်တောင် မပြားဘဲ စက်ဝိုင်းကို ဖြည့်ပါတယ်။ Run ပြီး Tab key နဲ့ button ဆီ သွားကြည့်ပါ။
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Profile card</title>
<style>
:root {
--bg: #0f1117;
--surface: #141824;
--text: #eaf2ff;
--muted: #a8b3c3;
--accent: #77f5ff;
--accent-2: #ff4dcd;
--radius: 20px;
}
* { box-sizing: border-box; }
body {
margin: 0;
padding: 16px;
background: var(--bg);
font-family: system-ui, sans-serif;
}
.profile-card {
width: min(100%, 360px);
margin: 40px auto;
padding: 24px;
text-align: center;
color: var(--text);
background: linear-gradient(135deg, var(--surface), var(--bg));
border: 1px solid rgb(119 245 255 / 0.25);
border-radius: var(--radius);
box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
}
.avatar {
display: grid;
place-items: center;
width: 96px;
height: 96px;
margin-inline: auto;
border: 3px solid var(--accent);
border-radius: 50%;
font-size: 2rem;
font-weight: 700;
}
.profile-card h2 { margin: 16px 0 8px; font-size: 1.5rem; overflow-wrap: anywhere; }
.profile-card p { margin: 0; line-height: 1.7; color: var(--muted); }
.profile-button {
display: inline-block;
margin-top: 16px;
padding: 12px 18px;
color: #041013;
font-weight: 700;
text-decoration: none;
border-radius: 999px;
background: linear-gradient(135deg, var(--accent), var(--accent-2));
transition: transform 0.25s ease;
}
.profile-button:hover { transform: translateY(-2px); }
.profile-button:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.profile-button { transition: none; }
}
</style>
</head>
<body>
<article class="profile-card">
<div class="avatar" aria-hidden="true">TL</div>
<h2>ThutaTech Learner</h2>
<p>A future web creator learning CSS step by step.</p>
<a href="#" class="profile-button">View Portfolio</a>
</article>
</body>
</html>Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- Design tokens
--accent: #77f5ff;Accent အရောင်က avatar border၊ button gradient၊ focus outline သုံးနေရာမှာ ပေါ်ပါတယ်။ Token ပြောင်းရင် သုံးနေရာလုံး တပြိုင်နက် ပြောင်းပါတယ်။
- Fluid card width
width: min(100%, 360px);Body padding 16px ကြောင့် 320px screen မှာ နေရာ 288px ပဲ ရှိလို့ card က 288px ဖြစ်ပါတယ်။ ကျယ်တဲ့ screen မှာတော့ 360px မှာ ရပ်ပါတယ်။ Height မပေးထားလို့ စာများရင် card က အောက်ကို ရှည်ပါတယ်။
- Centred initials
place-items: center;display: grid နဲ့ place-items: center တွဲသုံးရင် "TL" က စက်ဝိုင်းရဲ့ အလယ်တည့်တည့် ရောက်ပါတယ်။ ဒေါင်လိုက်ရော အလျားလိုက်ပါ တစ်ကြောင်းတည်းနဲ့ centre လုပ်တာပါ။
- Long-name safety
.profile-card h2 { margin: 16px 0 8px; font-size: 1.5rem; overflow-wrap: anywhere; }Space မပါတဲ့ username ရှည်တစ်ခု ရောက်လာရင်တောင် card ကို မကျော်ဘဲ ခေါက်ပါတယ်။
- Keyboard focus
.profile-button:focus-visible {outline ကို ဖျက်မပစ်ဘဲ brand အရောင်နဲ့ ပြန်ဒီဇိုင်းလုပ်ထားပါတယ်။ outline-offset က outline ကို button အစွန်းကနေ 3px ခွာထားလို့ gradient ပေါ်မှာ ရှင်းရှင်း မြင်ရပါတယ်။
- Reduced motion
@media (prefers-reduced-motion: reduce) {Motion လျှော့ထားတဲ့ user တွေအတွက် transition ကို ဖြုတ်ပါတယ်။ Hover feedback ကတော့ ရှိနေဆဲပါ။
အပြာရင့် နောက်ခံပေါ်မှာ card တစ်ခု အလယ်မှာ ပေါ်ပါတယ်။ 1024px မှာ card က 360px၊ 320px မှာ 288px ကျယ်ပြီး ဘေးတိုက် scroll မရှိပါ။ Avatar စက်ဝိုင်း၊ နာမည်၊ ဖော်ပြချက်နဲ့ gradient button ပါပြီး button ကို hover လုပ်ရင် 2px မြင့်တက်၊ Tab နဲ့ ရောက်ရင် အပြာနုရောင် outline ပေါ်ပါတယ်။Definition of done checklist
Project တစ်ခုကို portfolio ထဲ မထည့်ခင် ဒီ checklist ကို တစ်ခုချင်း စစ်ပါ။ အချက်တိုင်းက browser မှာ မိနစ်ပိုင်းပဲ ကြာပြီး user အစစ်တွေ တကယ်တွေ့မယ့် ပြဿနာတွေကို ဖမ်းပေးပါတယ်။
- 320px width မှာ ဘေးတိုက် scrollbar မပေါ်ဘူး
- Space မပါတဲ့ နာမည်ရှည်နဲ့ ဖော်ပြချက် မပါတဲ့ card က layout ကို မဖျက်ဘူး
- Browser zoom 200% မှာ စာအားလုံး ဖတ်လို့ရပြီး ထပ်မနေဘူး
- Tab key နဲ့ link/button တိုင်းကို ရောက်ပြီး focus ကို ရှင်းရှင်း မြင်ရတယ်
- Reduced motion ဖွင့်ထားရင် transition မရှိဘူး
လက်တွေ့ project တွေမှာ
လက်တွေ့ project တွေမှာ
Team page တွေ၊ marketplace seller profile တွေ၊ conference speaker list တွေမှာ ဒီ card pattern ကို နေရာတိုင်း တွေ့ရပါတယ်။ Real project မှာ ဒီ card ကို တစ်ခုတည်း မသုံးဘဲ CMS ထဲက data နဲ့ အခု ၂၀၊ ၅၀ ထုတ်ပါတယ်။ ဒါကြောင့် နာမည်ရှည်၊ ဖော်ပြချက် မပါတာ၊ ပုံ မရှိတာ စတဲ့ "ပုံမှန်မဟုတ်တဲ့" data တွေက အမြဲ ရောက်လာပါတယ်။ Component library တွေမှာ ဒီလို edge case တွေကို Storybook လို tool မှာ story တစ်ခုစီ ထားပြီး စမ်းလေ့ရှိပါတယ်။
Token တွေကလည်း project ကြီးလာတာနဲ့ အရေးပါလာပါတယ်။ Brand အရောင် ပြောင်းရင် ဒါမှမဟုတ် light theme ထည့်ရင် :root ထဲက value တွေကိုပဲ ပြောင်းပါတယ်။ Company အများစုမှာ focus outline ကို ဖျက်ခွင့် မပြုတဲ့ accessibility rule ရှိပြီး code review မှာ outline: none ကို တွေ့ရင် အမြဲ မေးခွန်းထုတ်ပါတယ်။
အမှားများ
ဖြစ်လေ့ရှိတဲ့ အမှားများ
Focus outline ကို ဖျက်ပစ်တာ
outline: none (ဒါမှမဟုတ် outline: 0) ကို အစားထိုး style မပေးဘဲ ရေးလိုက်ရင် keyboard user တွေ page ပေါ်မှာ လမ်းပျောက်ပါတယ်။ Outline ကို မကြိုက်ရင် ဖျက်မပစ်ဘဲ :focus-visible နဲ့ brand အရောင်၊ အထူ၊ offset ကို ပြန်ဒီဇိုင်းလုပ်ပါ။
Card ကို ပုံသေ height နဲ့ ချုပ်တာ
Card တွေ အမြင့်ညီချင်လို့ height: 420px ပေးရင် စာများတဲ့ card က content လျှံထွက်ပါတယ်။ အမြင့်ညီချင်ရင် card တွေကို grid ဒါမှမဟုတ် flex row ထဲ ထည့်ပါ။ Item တွေက default stretch နဲ့ အမြင့် အလိုအလျောက် ညီပါတယ်။
Hard-coded အရောင်တွေ ပြန့်ကျဲနေတာ
#77f5ff ကို rule ငါးခုမှာ ကူးရေးထားရင် brand အရောင် ပြောင်းတဲ့နေ့မှာ တစ်နေရာ ကျန်ခဲ့တတ်ပါတယ်။ Card တစ်ခုထဲမှာ နှစ်ကြိမ်ထက် ပိုပေါ်တဲ့ value တိုင်းကို token အဖြစ် ထားပါ။
Mini challenge
Team section တစ်ခု ဆောက်ပါ
Profile card သုံးခုပါတဲ့ team section တစ်ခု ဆောက်ပါ။ Card တစ်ခုမှာ နာမည် အရှည်ကြီး ပါပြီး တစ်ခုမှာ ဖော်ပြချက် စာပိုဒ် ရှည်ပါတယ်။ Card တွေက screen အကျယ်နဲ့ လိုက်ပြီး wrap ဖြစ်ရပြီး button တွေ အောက်ခြေမှာ တန်းညီနေရပါမယ်။
- Token တွေ (--accent၊ --surface၊ --radius) ကို :root ထဲ ထားပါ
- .team က repeat(auto-fit, minmax(240px, 1fr)) grid ဖြစ်ပြီး width: min(100% - 32px, 1000px) ရှိရပါမယ်
- Card တစ်ခုစီက flex column ဖြစ်ပြီး button ကို margin-top: auto နဲ့ အောက်ခြေကို တွန်းပါ
- Button မှာ :focus-visible outline ရှိရပြီး နာမည်ရှည်က card ထဲမှာ ခေါက်ရပါမယ်
/* Markup: section.team > article.member*3,
each with h3, p and a.member__link */
:root {
/* TODO: --accent, --surface, --text, --radius */
}
.team {
/* TODO: auto-fit grid, gap, fluid width, centred */
}
.member {
/* TODO: flex column, padding, surface background, radius */
}
.member h3 {
/* TODO: long names must wrap */
}
.member__link {
/* TODO: pinned to the bottom of the card */
}
/* TODO: :focus-visible outline for .member__link */ရလဒ်: 375px မှာ card သုံးခု ဒေါင်လိုက် တစ်ခုစီ၊ 1024px မှာ card သုံးခု တစ်တန်းတည်း ဖြစ်ပြီး card အမြင့်တွေ ညီကာ button သုံးခုလုံး တူညီတဲ့ အမြင့်မှာ တန်းစီပါတယ်။ နာမည်ရှည်က card ထဲမှာပဲ ခေါက်ပြီး page မှာ ဘေးတိုက် scroll မရှိပါ။
အရိပ်အမြွက် ကြည့်ရန်
Grid item တွေက default အားဖြင့် တန်းတစ်ခုထဲမှာ အမြင့်ညီပါတယ်။ Card ကို flex column လုပ်ပြီး link ကို margin-top: auto ပေးရင် ကျန်တဲ့ နေရာ အားလုံးကို link အပေါ်မှာ ထားပေးလို့ button တွေ အောက်ခြေမှာ တန်းညီပါတယ်။ align-self: start ထည့်ရင် link က card အကျယ် အပြည့် မဆွဲပါဘူး။
အဖြေ ကြည့်ရန်
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
--accent: #77f5ff;
--surface: #141824;
--text: #eaf2ff;
--radius: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; background: #0f1117; color: var(--text); font-family: system-ui; }
.team {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 24px;
width: min(100% - 32px, 1000px);
margin: 32px auto;
}
.member {
display: flex;
flex-direction: column;
padding: 20px;
background: var(--surface);
border-radius: var(--radius);
}
.member h3 { margin: 0 0 8px; overflow-wrap: anywhere; }
.member p { margin: 0 0 16px; color: #a8b3c3; }
.member__link {
margin-top: auto;
align-self: start;
padding: 10px 16px;
border-radius: 999px;
background: var(--accent);
color: #041013;
font-weight: 700;
text-decoration: none;
}
.member__link:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
</style>
</head>
<body>
<section class="team">
<article class="member">
<h3>Su Su</h3>
<p>Designer.</p>
<a class="member__link" href="#">Profile</a>
</article>
<article class="member">
<h3>AungKyawThuHtetNaingSeniorFrontendEngineer</h3>
<p>Builds the design system.</p>
<a class="member__link" href="#">Profile</a>
</article>
<article class="member">
<h3>Hnin Wai</h3>
<p>Writes the tutorials, reviews every lesson and answers questions daily.</p>
<a class="member__link" href="#">Profile</a>
</article>
</section>
</body>
</html>Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- Content နဲ့ semantic HTML ကနေ စပြီး token၊ component၊ state၊ stress test အစဉ်နဲ့ ဆောက်ပါ
- width: min(100%, 360px) သုံးပြီး height ကို content ကို ဆုံးဖြတ်ခိုင်းပါ
- Outline ကို မဖျက်ဘဲ :focus-visible နဲ့ ပြန်ဒီဇိုင်းလုပ်ပြီး reduced motion ကို လေးစားပါ
- 320px၊ နာမည်ရှည်၊ zoom 200%၊ Tab key နဲ့ စမ်းပြီးမှ "ပြီးပြီ" လို့ ပြောပါ
CSS reference — MDN Web Docs