:nth-child()
W3C CSS Snapshot 2026
Parent တူတဲ့ element တွေကို ၁ ကစပြီး ရေတွက်ကာ အစဉ်အလိုက် ရွေးပါတယ်။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
ရေးပုံနဲ့ သုံးလို့ရတဲ့ တန်ဖိုးများ
| တန်ဖိုး သို့မဟုတ် ရေးပုံ | အလုပ်လုပ်ပုံ |
|---|---|
:nth-child(2) | ဒုတိယ child element ကို ရွေးပါတယ်။ |
:nth-child(even) | ၂၊ ၄၊ ၆ စတဲ့ စုံကိန်းနေရာတွေကို ရွေးပါတယ်။ |
:nth-child(odd) | ၁၊ ၃၊ ၅ စတဲ့ မကိန်းနေရာတွေကို ရွေးပါတယ်။ |
:nth-child(3n + 1) | ၁၊ ၄၊ ၇ စတဲ့ နေရာတွေကို ရွေးပါတယ်။ |
:nth-child(2 of .task) | .task နဲ့ ကိုက်တဲ့ sibling တွေထဲက ဒုတိယတစ်ခုကို ရွေးပါတယ်။ |
နမူနာကို စမ်းကြည့်ပါ
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>:nth-child()</title>
<style>
li:nth-child(even) { background: #def5f5; }
</style>
</head>
<body>
<ul>
<li>Check in</li>
<li>Pick up materials</li>
<li>Find a seat</li>
<li>Start the activity</li>
</ul>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ ဒုတိယနဲ့ စတုတ္ထ item မှာ နောက်ခံရောင် ပေါ်ပါတယ်။ even ကို odd ပြောင်းစမ်းပါ။