在 HTML 中表格的内容要上下左右居中,可以使用 CSS 来实现。
你可以使用 margin: auto
属性将表格居中:
<style>
table {
margin: auto;
}
</style>
<table>
<!-- 表格内容 -->
</table>
你也可以使用 text-align: center
属性将表格中的文本居中:
<style>
td {
text-align: center;
}
</style>
<table>
<tr>
<td>表格内容</td>
</tr>
</table>
如果你想将表格中的所有单元格都居中,可以使用 vertical-align: middle
属性:
<style>
td {
vertical-align: middle;
text-align: center;
}
</style>
<table>
<tr>
<td>表格内容</td>
</tr>
</table>