HTML Attributes
HTML Living Standard
HTML element တစ်ခုရဲ့ အချက်အလက် ထပ်ဖြည့်ဖို့ ဒါမှမဟုတ် လုပ်ဆောင်ပုံ သတ်မှတ်ဖို့ အဖွင့် tag ထဲမှာ attribute ထည့်ရေးပါတယ်။ Standard Attributes ဆိုတာ HTML Standard က သတ်မှတ်ထားတဲ့ attribute တွေပါ။ အဲဒီထဲမှာ Global Attributes ရော သက်ဆိုင်ရာ element တွေမှာပဲ သုံးလို့ရတဲ့ attribute တွေရော ပါပါတယ်။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
Attribute တွေ အလုပ်လုပ်ပုံ
id နဲ့ class လို Global Attributes တွေကို HTML element အားလုံးမှာ သုံးလို့ရပါတယ်။ id တန်ဖိုးတစ်ခုကို စာမျက်နှာတစ်ခုထဲမှာ element တစ်ခုအတွက်ပဲ သုံးပါ။ Element အများကြီးကို CSS နဲ့ ပုံစံတူ ပြင်ချင်ရင် class တစ်ခုတည်းကို ပြန်သုံးလို့ရပါတယ်။ တချို့ attribute တွေကိုတော့ သက်ဆိုင်ရာ element တွေမှာပဲ သုံးရပါတယ်။ <a> မှာ href က link ရဲ့ သွားမယ့်နေရာကို သတ်မှတ်ပါတယ်။ <img> မှာ src က ပုံရဲ့ လိပ်စာဖြစ်ပြီး alt က ပုံနေရာမှာ ဖတ်လို့ရမယ့် စာသားပါ။
စမ်းသပ်နည်း ဒီနမူနာကို .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>How Attributes Work</title>
<style>
.highlight { color: teal; }
h2:target { outline: 2px solid teal; }
</style>
</head>
<body>
<a class="highlight" href="#schedule">View schedule</a>
<h2 id="schedule" class="highlight">Schedule</h2>
<p>Classes begin at 10:00 AM.</p>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ Link နဲ့ ခေါင်းစဉ် နှစ်ခုလုံးမှာ class="highlight" ပါလို့ စိမ်းပြာရောင် ပေါ်ပါတယ်။ View schedule ကို နှိပ်ရင် link ရဲ့ href ထဲက #schedule နဲ့ ကိုက်ညီတဲ့ id="schedule" ရှိတဲ့ ခေါင်းစဉ်ဆီ ရောက်ပါမယ်။