HTML教程-HTML<tr>标签
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>
属性:
特定于标签的属性:
属性 | 值 | 描述 |
---|---|---|
align | right、left、center、justify、char | 定义表格行内容的对齐方式。 (在 HTML5 中不再支持) |
bgcolor | rgb(x,x,x)、#xxxxx、color_name | 定义表格行的背景颜色。 (在 HTML5 中不再支持) |
char | character | 指定内容相对于字符的对齐方式。 (在 HTML5 中不再支持) |
charoff | number | 指定表格行内容相对于字符的对齐偏移量,该字符由 char 属性指定。 (在 HTML5 中不再支持) |
valign | top、middle、bottom、baseline | 指定表格行内容的垂直对齐方式。 (在 HTML5 中不再支持) |
全局属性:
<tr>
标签支持 HTML 中的全局属性。
事件属性:
<tr>
标签支持 HTML 中的事件属性。
支持的浏览器
元素 | Chrome | IE | Firefox | Opera | Safari |
---|---|---|---|---|---|
<tr> | 是 | 是 | 是 | 是 | 是 |