HTML - headers 屬性



HTML headers 屬性用於在包含當前資料單元標題資訊的表格單元格中指定一個或多個標題單元格。

此屬性包含一個空格分隔的字串列表,每個字串對應於應用於此元素的<th>元素的id屬性。它還指定了一個或多個屬於該表格單元格的標題單元格。

語法

<tag headers = "header_id"></tag>

應用於

以下列出的元素允許使用 HTML headers 屬性

元素 描述
<th> HTML <th> 標籤用於在表格中定義標題單元格
<td> HTML <td> 用於在表格中定義單元格。

HTML headers 屬性示例

以下示例將說明 HTML height 屬性,以及我們應該在哪裡以及如何使用此屬性!

th 標籤內的 headers 屬性

在以下示例中,我們在<th>標籤內使用 HTML 'header' 屬性來指定名字和姓氏屬於姓名。

<!DOCTYPE html>
<html lang="en">

<head>
    <title>HTML 'headers' Attribute</title>
    <style>
        table,
        th,
        td {
           border: 1px solid black;
        }
    </style>
</head>

<body>
    <!--HTML 'headers' attribute-->
    <h3>Example of the HTML 'headers' attribute</h3>
    <table>
        <tr>
            <th id='name' colspan="2">Full Name</th>
        </tr>
        <tr>
            <th headers="name">First Name</th>
            <th headers="name">Last Name</th>
        </tr>
    </table>
</body>

</html>

td 標籤內的 headers 屬性

考慮另一種情況,我們將使用 header 屬性與 td 元素。

<!DOCTYPE html>
<html lang="en">

<head>
    <title>HTML 'headers' attribute</title>
    <style>
        table,
        th,
        td {
           border: 1px solid black;
        }
    </style>
</head>

<body>
    <!--HTML 'headers' attribute-->
    <h3>Example of the HTML 'headers' attribute</h3>
    <table>
        <tr>
            <th id="name">Name</th>
            <th id="email">Email</th>
            <th id='mobile'>Mobile</th>
            <th id='address'>Address</th>
        </tr>
        <tr>
            <td headers="name">Aman</td>
            <td headers="email">aman123@gmail.com</td>
            <td headers="mobile">9012345567</td>
            <td headers="address">Ranchi Jharkhand</td>
        </tr>
    </table>
</body>

</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
headers
html_attributes_reference.htm
廣告

© . All rights reserved.