HTML headers 属性用于指定表单元格中的一个或多个标题单元格,其中包含当前数据单元格的标题信息。
此属性包含一个以空格分隔的字符串列表,每个字符串对应于应用于此元素的第 <th>元素的 id 属性。它还指定表单元格所属的一个或多个标题单元格。
语法
<tag headers = "header_id"></tag>
适用于
下面列出的元素允许使用 HTML headers 属性
元素 | 描述 |
---|---|
<th> | HTML <th> 标签用于定义表中的标题单元格 |
<td> | HTML <td> 用于定义表格中的单元格。 |
HTML headers 属性的示例
以下示例将说明 HTML height 属性,我们应该在哪里以及如何使用此属性!
第 Tag 内的 Headers 属性
在以下示例中,我们在 <th> 标签中使用 HTML 'header' 属性来指定名字和姓氏属于 Name。
<!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 属性
考虑到另一种情况,我们将使用带有 td 元素的 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">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>
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
是否支持 | Yes | Yes | Yes | Yes | Yes |