代码拉取完成,页面将自动刷新
一个包含三行、两个标题单元格和四个数据单元格的简单 HTML 表格:
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
<th>
标记定义 HTML 表格中的标题单元格。
HTML 表格有两种单元格:
<th>
元素创建)<th>
元素中的文本默认为粗体并居中。
<td> 元素中的文本默认为常规且左对齐。
Element | |||||
---|---|---|---|---|---|
<th> | Yes | Yes | Yes | Yes | Yes |
属性 | 值 | 描述 |
---|---|---|
abbr | text | 指定标题单元格中内容的缩写版本 |
colspan | number | 指定标题单元格应跨越的列数 |
headers | header_id | 指定一个或多个与单元格相关的标题单元格 |
rowspan | number | 指定标题单元格应跨越的行数 |
scope | col colgroup row rowgroup | 指定标题单元格是否是列、行或列或行组的标题 |
<th>
标签支持 HTML 中的全局属性。
<th>
标签支持 HTML 中的事件属性。
如何对齐 <td> 中的内容(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td style="text-align:right">$100</td>
</tr>
<tr>
<td>February</td>
<td style="text-align:right">$80</td>
</tr>
</table>
如何向表格单元格添加背景颜色(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="background-color:#FF0000">January</td>
<td style="background-color:#00FF00">$100</td>
</tr>
</table>
如何设置表格单元格的高度(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="height:100px">January</td>
<td style="height:100px">$100</td>
</tr>
</table>
如何在表格单元格中指定不换行(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>Poem</th>
</tr>
<tr>
<td style="white-space:nowrap">Never increase, beyond what is necessary, the number of entities required to explain anything</td>
</tr>
</table>
如何垂直对齐 <td> 中的内容(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table style="width:50%;">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="height:100px">
<td style="vertical-align:bottom">January</td>
<td style="vertical-align:bottom">$100</td>
</tr>
</table>
如何设置表格单元格的宽度(使用 CSS):
<style>
table, th, td { border: 1px solid black; }
</style>
<table style="width:100%">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="width:70%">January</td>
<td style="width:30%">$100</td>
</tr>
</table>
如何创建表头:
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>姓名</th>
<th>邮箱</th>
<th colspan="2">电话</th>
</tr>
<tr>
<td>周杰伦</td>
<td>zhou@example.com</td>
<td>123-45-678</td>
</tr>
</table>
如何创建带有标题的表格:
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
如何定义跨越多于一行或一列的表格单元格:
<style>
table, th, td { border: 1px solid black; }
</style>
<table>
<tr>
<th>姓名</th>
<th>邮箱</th>
<th colspan="2">电话</th>
</tr>
<tr>
<td>周杰伦</td>
<td>zhou@example.com</td>
<td>123-45-678</td>
<td>021-00-546</td>
</tr>
</table>
HTML 教程: HTML Tables
大多数浏览器将显示具有以下默认值的 <th>
元素:
th {
display: table-cell;
vertical-align: inherit;
font-weight: bold;
text-align: center;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。