Custom Property နဲ့ Cascade Layer
W3C CSS Snapshot 2026
တန်ဖိုးတွေကို custom property နဲ့ ပြန်သုံးပါ။ Rule အုပ်စုတွေကို ဘယ်အစဉ်နဲ့ ဦးစားပေးမလဲဆိုတာ cascade layer နဲ့ သတ်မှတ်ပါ။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
Custom Properties နဲ့ တန်ဖိုးပြန်သုံးခြင်း
Custom property က ကိုယ်ပေးထားတဲ့ နာမည်နဲ့ CSS တန်ဖိုးတစ်ခုပါ။ နာမည်ကို -- နဲ့ စပါတယ်။ :root က အပြင်ဆုံး element ကို ရွေးလို့ အောက်က element တွေက တန်ဖိုးကို ဆက်ယူနိုင်ပါတယ်။ var(--accent, teal) က --accent တန်ဖိုးကို ဖတ်ပြီး အဲဒီ property မရှိရင် teal ကို အစားထိုးသုံးပါတယ်။
စမ်းသပ်နည်း ဒီနမူနာကို .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>Reuse values with custom properties</title>
<style>
:root { --accent: purple; }
.notice { color: var(--accent, teal); }
</style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ ပထမစာပိုဒ်က ခရမ်းရောင် ဖြစ်ပါမယ်။ --accent သတ်မှတ်ချက်ကို ဖျက်ရင် စိမ်းပြာရောင် ပြောင်းပါမယ်။
@layer နဲ့ Rule အုပ်စုတွေကို အစဉ်သတ်မှတ်ခြင်း
Cascade layer ဆိုတာ rule တွေကို ဦးစားပေးအုပ်စု နာမည်တပ်ပြီး ခွဲထားတာပါ။ တူညီတဲ့ရင်းမြစ်က ပုံမှန်သတ်မှတ်ချက်တွေမှာ selector အား ဘယ်လောက်ရှိလဲ မနှိုင်းခင် နောက်အလွှာက ရှေ့အလွှာထက် အနိုင်ရပါတယ်။ Layer အစဉ်ကို အရင် ကြေညာပါ။ Layer အပြင်မှာရှိတဲ့ ပုံမှန်သတ်မှတ်ချက်က layer ထဲက သတ်မှတ်ချက်တွေထက် ဦးစားရပါတယ်။
စမ်းသပ်နည်း ဒီနမူနာကို .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>Order groups of rules with @layer</title>
<style>
@layer base, theme;
@layer base { .notice { color: teal; } }
@layer theme { p { color: purple; } }
</style>
</head>
<body>
<p class="notice">Your order is ready.</p>
<p>Your package is on the way.</p>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ theme က နောက်အလွှာဖြစ်လို့ စာပိုဒ်နှစ်ခုလုံး ခရမ်းရောင် ဖြစ်ပါမယ်။