在 HTML 中,可以使用三種方法使表格居中:使用 margin: auto; 屬性使表格水平居中。使用 text-align: center; 屬性在父元素內(nèi)垂直居中表格。使用 align 屬性指定表格相對(duì)于父元素的位置(棄用)。
如何讓 HTML 表格居中
在 HTML 中,有幾種方法可以使表格居中:
1. 使用 margin: auto;
示例:
立即學(xué)習(xí)“前端免費(fèi)學(xué)習(xí)筆記(深入)”;
<table style="margin: auto;"> <tr> <th>列 1</th> <th>列 2</th> </tr> <tr> <td>數(shù)據(jù) 1</td> <td>數(shù)據(jù) 2</td> </tr> </table>
2. 使用 text-align: center;
示例:
立即學(xué)習(xí)“前端免費(fèi)學(xué)習(xí)筆記(深入)”;
<div style="text-align: center;"> <table border="1"> <tr> <th>列 1</th> <th>列 2</th> </tr> <tr> <td>數(shù)據(jù) 1</td> <td>數(shù)據(jù) 2</td> </tr> </table> </div>
3. 使用 align 屬性
示例:
立即學(xué)習(xí)“前端免費(fèi)學(xué)習(xí)筆記(深入)”;
<table align="center"> <tr> <th>列 1</th> <th>列 2</th> </tr> <tr> <td>數(shù)據(jù) 1</td> <td>數(shù)據(jù) 2</td> </tr> </table>
注意:
以上就是html中表格怎么居中的詳細(xì)內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
HTML怎么學(xué)習(xí)?HTML怎么入門?HTML在哪學(xué)?HTML怎么學(xué)才快?不用擔(dān)心,這里為大家提供了HTML速學(xué)教程(入門課程),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)