Pseudo-element နဲ့ အစိတ်အပိုင်း ပြင်ခြင်း
W3C CSS Snapshot 2026
Pseudo-element က element ရဲ့ အစိတ်အပိုင်းတစ်ခုကို ရွေးပေးတာ ဒါမှမဟုတ် style ပေးလို့ရမယ့် အစိတ်အပိုင်းတစ်ခု ဖန်တီးပေးတာပါ။ နာမည်ရှေ့မှာ :: နဲ့ စရေးပါတယ်။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
::before နဲ့ ::after သုံးပြီး အလှဆင်ခြင်း
content သတ်မှတ်ရင် ::before နဲ့ ::after က element ထဲက အကြောင်းအရာ မတိုင်ခင်နဲ့ ပြီးတဲ့နောက်မှာ နှစ်ဖက်စလုံး ထပ်ထည့်နိုင်ပါတယ်။ စာသားအလွတ်ဆို style ပေးလို့ရမယ့် အကွက်အလွတ် ရပါတယ်။ အရေးကြီးတဲ့အချက်ကို ဖတ်သူနဲ့ assistive tools တွေ သိနိုင်ဖို့ HTML ထဲမှာ ရေးထားပါ။
စမ်းသပ်နည်း ဒီနမူနာကို .html ဖိုင်အသစ်အဖြစ် သိမ်းပြီး browser နဲ့ ဖွင့်ပါ။ ပြင်ပြီးတိုင်း save နဲ့ reload လုပ်ပါ။
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Add decoration with ::before and ::after</title>
<style>
.notice::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: teal; }
.notice::after { content: ""; display: inline-block; width: 16px; height: 2px; margin-left: 6px; background: teal; }
</style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ “Your order is ready.” ရှေ့မှာ စိမ်းပြာရောင် အစက်၊ နောက်မှာ မျဉ်းတို ပေါ်ပါမယ်။ Rule တစ်ခုက content ကို ဖြုတ်ရင် အဲဒီ rule ရဲ့ အလှဆင်အပိုင်း ပျောက်ပါမယ်။
အစိတ်အပိုင်းနဲ့ အခြေအနေကို ရွေးခြင်း
::first-letter က စာပိုဒ်ထဲက ပထမစာလုံးကို style ပေးပါတယ်။ :hover လို pseudo-class ကတော့ element တစ်ခုလုံးရဲ့ လက်ရှိအခြေအနေကို စစ်ပါတယ်။ Selector နောက်မှာ လိုတဲ့တစ်မျိုးကို တွဲရေးနိုင်ပါတယ်။
စမ်းသပ်နည်း ဒီနမူနာကို .html ဖိုင်အသစ်အဖြစ် သိမ်းပြီး browser နဲ့ ဖွင့်ပါ။ ပြင်ပြီးတိုင်း save နဲ့ reload လုပ်ပါ။
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Style a part or match a state</title>
<style>
.notice::first-letter { font-weight: bold; font-size: 1.8em; }
.notice:hover { color: purple; }
</style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ Pen ရဲ့ ပထမစာလုံး ပိုကြီးပါမယ်။ စာပိုဒ်ပေါ် mouse တင်ပြီး အရောင်ပြောင်းပုံကို ကြည့်ပါ။