ข้อมูลอ้างอิงHTML

HTML โดยตัวอักษร HTML ตามหมวดหมู่ รองรับ HTML Browser แอตทริบิวต์ HTML HTML Global Attributes เหตุการณ์ HTML HTML สี HTML Canvas HTML เสียง/วิดีโอ ชุดอักขระ HTML HTML Doctypes การเข้ารหัส URL HTML รหัสภาษา HTML รหัสประเทศ HTML ข้อความ HTTP วิธี HTTP ตัวแปลง PX เป็น EM แป้นพิมพ์ลัด


HTML <col>แท็ก


ตัวอย่าง

กำหนดสีพื้นหลังของสามคอลัมน์ด้วยแท็ก <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>

ตัวอย่าง "ลองใช้เอง" เพิ่มเติมด้านล่าง


ความหมายและการใช้งาน

แท็ ก<col>ระบุคุณสมบัติของคอลัมน์สำหรับแต่ละคอลัมน์ภายใน องค์ประกอบ<colgroup>

แท็ ก<col>มีประโยชน์สำหรับการนำสไตล์ไปใช้กับทั้งคอลัมน์ แทนที่จะใช้สไตล์ซ้ำสำหรับแต่ละเซลล์ สำหรับแต่ละแถว


รองรับเบราว์เซอร์

Element
<col> Yes Yes Yes Yes Yes

คุณลักษณะ

Attribute Value Description
span number Specifies the number of columns a <col> element should span

คุณสมบัติสากล

แท็ ก<col>ยังสนับสนุน Global Attributes ในHTML


คุณสมบัติของเหตุการณ์

แท็ ก<col>ยังสนับสนุนแอตทริบิวต์เหตุการณ์ใน 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:130px">Month</th>
    <th style="width:80px">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

หน้าที่เกี่ยวข้อง

การอ้างอิง HTML DOM: วัตถุคอลัมน์


การตั้งค่า CSS เริ่มต้น

เบราว์เซอร์ส่วนใหญ่จะแสดง<col>องค์ประกอบด้วยค่าเริ่มต้นดังต่อไปนี้:

ตัวอย่าง

col {
  display: table-column;
}