HTML <caption> 标签用于添加 HTML 表格的标题或标题。它应该在 <table> 元素内使用,并紧跟在 <table> 的起始标签后面。一个表格只能包含一个 <caption> 元素。

语法

<caption>Table title...</caption>

以下是 <caption> 标签的一些规范:

属性
显示内联
开始标签/结束标签都有开始和结束标签
用法文本

示例 1

<!DOCTYPE html>
<html>
<head>
  <title>Caption Tag</title>
  <style>
    table, td, th {
      border: 3px solid gray;
      border-collapse: collapse;
    }
  </style>
</head>
<body>
  <h2>Example of Caption tag</h2>
  <table width="800">
    <caption>Employee Details</caption>
    <thead>
      <tr>
        <th>Sr. No.</th>
        <th>Name</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1.</td>
        <td>Ankit Pandey</td>
        <td>ankit2@gmail.com</td>
      </tr>
      <tr>
        <td>2.</td>
        <td>Ashvini Kumar</td>
        <td>ashvini@gmail.com</td>
      </tr>
      <tr>
        <td>3.</td>
        <td>Swati Sharma</td>
        <td>swati8@gmail.com</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

输出
uTools_1686112334552.png

属性

特定于标签的属性

属性描述
aligntopbottomleftright根据表格对齐标题

全局属性

<caption> 标签支持全局属性。

事件属性

<caption> 标签支持事件属性。

支持的浏览器

元素chrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<caption>

标签: html, HTML教程, HTML技术, HTML学习, HTML学习教程, HTML下载, HTML语言, HTML开发, HTML入门教程, HTML进阶教程, HTML高级教程, HTML面试题, HTML笔试题, HTML编程思想