📅  最后修改于: 2023-12-03 15:01:18.209000             🧑  作者: Mango
在 HTML 的表格标签中,<th>
是表头单元格的标签,而 charoff
属性则是用来设定单元格内容与单元格边框之间的距离,即表格的字符偏移量。
charoff
属性被应用于 <th>
标签中,语法如下:
<th charoff="number|percentage">
其中,number
表示以像素为单位的距离值,而 percentage
则表示以单元格宽度为百分比的距离值,可取值为 0 到 100。
以下实例演示如何使用 charoff
属性来设定表格单元格与边框之间的距离:
<table border="1">
<tr>
<th charoff="10">Name</th>
<th charoff="20%">Age</th>
<th>Email</th>
</tr>
<tr>
<td>John Doe</td>
<td>35</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Jane Doe</td>
<td>29</td>
<td>jane@example.com</td>
</tr>
</table>
实现效果如下:
Name | Age | |
---|---|---|
John Doe | 35 | john@example.com |
Jane Doe | 29 | jane@example.com |
如上所示,第一个表头单元格的 charoff
值为 10 像素,第二个表头单元格的 charoff
值为单元格宽度的 20%。
charoff
属性只适用于带有边框的表格。charoff
属性的单元格,默认为 0。