設(shè)置方法:1、利用align屬性,語(yǔ)法“<td align="center">…</td>”;2、利用style屬性添加居中對(duì)齊樣式,語(yǔ)法“<td style="text-align: center;">…</td>”。
本教程操作環(huán)境:windows7系統(tǒng)、HTML5版、Dell G3電腦。
HTML設(shè)置td內(nèi)容居中
1、利用align屬性
align 屬性規(guī)定單元格中內(nèi)容的水平對(duì)齊方式。當(dāng)屬性值為“center”,設(shè)置居中對(duì)齊內(nèi)容。
<table border="1" width="200"> <tr> <th>姓名</th> <th>年齡</th> </tr> <tr> <td align="center">Peter</td> <td>20</td> </tr> <tr> <td>Lois</td> <td>20</td> </tr> </table>
2、利用style屬性添加居中對(duì)齊樣式
<table border="1" width="200"> <tr> <th>姓名</th> <th>年齡</th> </tr> <tr> <td>Peter</td> <td>20</td> </tr> <tr> <td style="text-align: center;">Lois</td> <td>20</td> </tr> </table>