HTML <tr> 标签用于定义表格中的行。该标签用于表示表格的一行,可以包含一个或多个 <th> 表头单元格和 <td> 数据单元格。

<tr> 标签必须是 <table> 元素的直接子元素,或者可以嵌套在 <thead><tbody><tfoot> 元素中。

语法

<tr>...</tr>

HTML <tr> 标签是内联元素,包含开始标签和结束标签。

示例

<!DOCTYPE html>
<html>
<head>
  <title>HTML tr tag</title>
  <style>
    table {
      border-collapse: collapse;
      margin-left: 350px;
    }
    th, td {
      padding: 25px;
    }
    th {
      background-color: #005cb9;
    }
    td {
      background-color: #98f5ff;
    }
  </style>
</head>
<body>
  <h2>tr 标签示例</h2>
  <table border="1">
    <caption><b>冬季奥运会奖牌前三名</b></caption>
    <tr>
      <th>排名</th>
      <th>国家</th>
      <th>总奖牌数</th>
    </tr>
    <tr>
      <td>1</td>
      <td>挪威</td>
      <td>329</td>
    </tr>
    <tr>
      <td>2</td>
      <td>美国</td>
      <td>282</td>
    </tr>
    <tr>
      <td>3</td>
      <td>德国</td>
      <td>228</td>
    </tr>
  </table>
</body>
</html>

属性:

特定于标签的属性:

属性描述
alignright、left、center、justify、char定义表格行内容的对齐方式。 (在 HTML5 中不再支持)
bgcolorrgb(x,x,x)、#xxxxx、color_name定义表格行的背景颜色。 (在 HTML5 中不再支持)
charcharacter指定内容相对于字符的对齐方式。 (在 HTML5 中不再支持)
charoffnumber指定表格行内容相对于字符的对齐偏移量,该字符由 char 属性指定。 (在 HTML5 中不再支持)
valigntop、middle、bottom、baseline指定表格行内容的垂直对齐方式。 (在 HTML5 中不再支持)

全局属性:

<tr> 标签支持 HTML 中的全局属性。

事件属性:

<tr> 标签支持 HTML 中的事件属性。

支持的浏览器

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

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