HTML <colgroup>แท็ก
ตัวอย่าง
กำหนดสีพื้นหลังของสามคอลัมน์ด้วยแท็ก <colgroup> และ <col>:
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
</table>
ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง
ความหมายและการใช้งาน
แท็ ก<colgroup>
ระบุกลุ่มของคอลัมน์ตั้งแต่หนึ่งคอลัมน์ขึ้นไปในตารางสำหรับการจัดรูปแบบ
แท็ ก<colgroup>
มีประโยชน์สำหรับการนำสไตล์ไปใช้กับทั้งคอลัมน์ แทนที่จะใช้สไตล์ซ้ำสำหรับแต่ละเซลล์ สำหรับแต่ละแถว
หมายเหตุ: แท็ ก<colgroup>
ต้องเป็นลูกขององค์ประกอบ <table> หลังองค์ประกอบ <caption> และก่อนองค์ประกอบ <thead>, <tbody>, <tfoot> และ <tr>
เคล็ดลับ:ในการกำหนดคุณสมบัติต่างๆ ให้กับคอลัมน์ภายใน a <colgroup>
ให้ใช้ แท็ก <col>ภายใน<colgroup>
แท็ก
รองรับเบราว์เซอร์
Element | |||||
---|---|---|---|---|---|
<colgroup> | Yes | Yes | Yes | Yes | Yes |
คุณลักษณะ
Attribute | Value | Description |
---|---|---|
span | number | Specifies the number of columns a column group should span |
คุณสมบัติสากล
แท็ ก<colgroup>
ยังสนับสนุน Global Attributes ในHTML
คุณสมบัติของเหตุการณ์
แท็ ก<colgroup>
ยังสนับสนุนแอตทริบิวต์เหตุการณ์ใน HTML
ตัวอย่างเพิ่มเติม
ตัวอย่าง
จัดข้อความในคอลัมน์ตาราง (ด้วย CSS):
<table style="width:100%">
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td style="text-align:right">$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td style="text-align:right">$47</td>
</tr>
</table>
ตัวอย่าง
ข้อความจัดแนวแนวตั้งในคอลัมน์ตาราง (พร้อม CSS):
<table style="height:200px">
<tr>
<th>Month</th>
<th
style="vertical-align:bottom">Savings</th>
</tr>
<tr>
<td>January</td>
<td
style="vertical-align:bottom">$100</td>
</tr>
</table>
ตัวอย่าง
ระบุความกว้างของคอลัมน์ตาราง (ด้วย CSS):
<table>
<tr>
<th
style="width:200px">Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
หน้าที่เกี่ยวข้อง
การอ้างอิง HTML DOM: ColumnGroup Object
การตั้งค่า CSS เริ่มต้น
เบราว์เซอร์ส่วนใหญ่จะแสดง<colgroup>
องค์ประกอบด้วยค่าเริ่มต้นดังต่อไปนี้:
ตัวอย่าง
colgroup {
display: table-column-group;
}