HTML ဇယားများ <table>
HTML Living Standard
Data table က row နဲ့ column တစ်လျှောက် တန်ဖိုးတွေ ဘယ်လို ဆက်စပ်လဲ ပြပါတယ်။ တန်ဖိုးတစ်ခုချင်း ဘာကို ဆိုလိုလဲ သိဖို့ HTML နဲ့ ခေါင်းစဉ်တွေ သတ်မှတ်ပေးနိုင်ပါတယ်။
Code စမ်းလို့ရတဲ့ သင်ခန်းစာ ဖွင့်ရန်
ဒီစာမျက်နှာမှာ
Table ရဲ့ Row၊ Cell နဲ့ Caption
table ထဲမှာ row တစ်ကြောင်းစီကို tr နဲ့ ရေးပါတယ်။ Data cell ကို td၊ header cell ကို th နဲ့ ရေးပါ။ မြင်ရတဲ့ table ခေါင်းစဉ်ဖြစ်တဲ့ caption ကို အစမှာ ထားပါတယ်။ thead က header rows တွေကို စုပေးပြီး tbody က data rows တွေကို စုပေးပါတယ်။ CSS မထည့်သေးလည်း browser က cells တွေကို columns အလိုက် စီပေးပါတယ်။
စမ်းသပ်နည်း index.html ထဲက <body> နဲ့ </body> ကြားမှာ ဒီနမူနာကို ထည့်ပါ။ ဖိုင်ကို သိမ်းပြီး browser မှာ reload လုပ်ပါ။
<table>
<caption>Product catalog</caption>
<thead>
<tr><th>Item</th><th>Price (MMK)</th></tr>
</thead>
<tbody>
<tr><td>Pen</td><td>1500</td></tr>
<tr><td>Notebook</td><td>2500</td></tr>
</tbody>
</table>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ Caption နဲ့ column နှစ်ခု ပေါ်ပါတယ်။ ပစ္စည်းတစ်ခုစီရဲ့ ဈေးနှုန်းက နာမည်နဲ့ row တစ်တန်းတည်းမှာ ပေါ်ပါတယ်။
scope နဲ့ Header ကို သက်ဆိုင်ရာ Cell တွေနဲ့ ချိတ်ခြင်း
ရိုးရှင်းတဲ့ data table မှာ scope="col" က သူ့ column ရဲ့ ခေါင်းစဉ်၊ scope="row" က သူ့ row ရဲ့ ခေါင်းစဉ်ဆိုတာ ပြပေးပါတယ်။ Screen reader လို assistive tool က cell တစ်ခုကို ဖတ်တဲ့အခါ သက်ဆိုင်ရာ ခေါင်းစဉ်တွေကိုပါ တွဲဖတ်ပေးနိုင်ပါတယ်။
စမ်းသပ်နည်း index.html ထဲက <body> နဲ့ </body> ကြားမှာ ဒီနမူနာကို ထည့်ပါ။ ဖိုင်ကို သိမ်းပြီး browser မှာ reload လုပ်ပါ။
<table>
<caption>Product prices</caption>
<tr><th scope="col">Product</th><th scope="col">Price (MMK)</th></tr>
<tr><th scope="row">Pen</th><td>1500</td></tr>
<tr><th scope="row">Notebook</th><td>2500</td></tr>
</table>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ 1500 ပါတဲ့ cell ရဲ့ row header က Pen ဖြစ်ပြီး column header က Price (MMK) ဖြစ်ပါတယ်။
<colgroup> နဲ့ <col> သုံးပြီး ဇယား Column သတ်မှတ်ခြင်း
ဇယားထဲက column တွေကို အုပ်စုဖွဲ့ဖို့ <colgroup> သုံးပါ။ <caption> နောက်၊ <thead> မတိုင်ခင် ထားပါ။ ဒီနမူနာထဲက <col> တစ်ခုစီက ဘယ်ကနေ ညာကို column တစ်ခုစီ ကိုယ်စားပြုပါတယ်။ ဒုတိယ <col> မှာ class ထည့်ထားလို့ ဈေးနှုန်း column ရဲ့ နောက်ခံအရောင်ကို CSS နဲ့ ပြောင်းနိုင်ပါတယ်။ ခေါင်းစဉ်နဲ့ တန်ဖိုးတွေကိုတော့ ပုံမှန်အတိုင်း <th> နဲ့ <td> ထဲမှာ ရေးပါ။
စမ်းသပ်နည်း ဒီနမူနာကို .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>Product prices</title>
<style>
.price-column { background-color: #dbeafe; }
</style>
</head>
<body>
<table>
<caption>Product prices</caption>
<colgroup>
<col>
<col class="price-column">
</colgroup>
<thead>
<tr><th scope="col">Item</th><th scope="col">Price (MMK)</th></tr>
</thead>
<tbody>
<tr><td>Pen</td><td>1500</td></tr>
<tr><td>Notebook</td><td>2500</td></tr>
</tbody>
</table>
</body>
</html>
စမ်းကြည့်ရင် ဘာဖြစ်မလဲ ဈေးနှုန်း column ရဲ့ နောက်ခံမှာ အပြာနုရောင် ပေါ်ပါတယ်။ Class ကို ပထမ <col> ဆီ ရွှေ့ကြည့်ရင် ပစ္စည်းနာမည် column မှာ အရောင် ပေါ်ပါမယ်။