HTML <tr>แท็ก
ตัวอย่าง
ตาราง HTML อย่างง่ายที่มีสามแถว หนึ่งแถวส่วนหัวและสองแถวข้อมูล:
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
แท็ ก<tr>
กำหนดแถวในตาราง HTML
องค์ประกอบ<tr>
ประกอบด้วยองค์ประกอบ<th>หรือ
<td>อย่างน้อยหนึ่งรายการ
รองรับเบราว์เซอร์
Element | |||||
---|---|---|---|---|---|
<tr> | Yes | Yes | Yes | Yes | Yes |
คุณสมบัติสากล
แท็ ก<tr>
ยังสนับสนุน Global Attributes ในHTML
คุณสมบัติของเหตุการณ์
แท็ ก<tr>
ยังสนับสนุนแอตทริบิวต์เหตุการณ์ใน HTML
ตัวอย่างเพิ่มเติม
ตัวอย่าง
วิธีจัดแนวเนื้อหาภายใน <tr> (ด้วย CSS):
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="text-align:right">
<td>January</td>
<td>$100</td>
</tr>
</table>
ตัวอย่าง
วิธีเพิ่มสีพื้นหลังให้กับแถวของตาราง (ด้วย CSS):
<table>
<tr style="background-color:#FF0000">
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
ตัวอย่าง
วิธีจัดแนวเนื้อหาในแนวตั้งภายใน <tr> (ด้วย CSS):
<table style="height:200px">
<tr
style="vertical-align:top">
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="vertical-align:bottom">
<td>January</td>
<td>$100</td>
</tr>
</table>
ตัวอย่าง
วิธีสร้างส่วนหัวของตาราง:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>John Doe</td>
<td>[email protected]</td>
<td>123-45-678</td>
</tr>
</table>
ตัวอย่าง
วิธีสร้างตารางพร้อมคำบรรยาย:
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
ตัวอย่าง
วิธีกำหนดเซลล์ตารางที่มีมากกว่าหนึ่งแถวหรือหนึ่งคอลัมน์:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th colspan="2">Phone</th>
</tr>
<tr>
<td>John Doe</td>
<td>[email protected]</td>
<td>123-45-678</td>
<td>212-00-546</td>
</tr>
</table>
หน้าที่เกี่ยวข้อง
กวดวิชา HTML: ตาราง HTML
การอ้างอิง HTML DOM: วัตถุ TableRow
กวดวิชา CSS: ตารางการจัดสไตล์
การตั้งค่า CSS เริ่มต้น
เบราว์เซอร์ส่วนใหญ่จะแสดง<tr>
องค์ประกอบด้วยค่าเริ่มต้นดังต่อไปนี้:
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}