我在表格上有一个很长的标题,并希望它们都彼此中心对齐。
HTML:
<table>
<caption>This is a very long caption.</caption>
<tr>
<td>1</td><td>2</td>
</tr>
<tr>
<td>3</td><td>4</td>
</tr>
</table>
CSS:
caption {
white-space: nowrap;
}
最佳答案
使用flexbox,使用align-items:center
table {
display: flex;
flex-direction: column;
align-items: center;
border: red solid
}
<table>
<caption>This is a very long caption.</caption>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
关于html - 如何使表格标题居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815155/