In an HTML table, how can I center the contents of the cells (not the table itself)?
Given that I'm allowed to use static JS and HTML tags (only those supported by IE6), how can I center the contents of the cells in an HTML table (not the tab开发者_JAVA技巧le itself)?
IE 6 supports CSS. In the head of the document:
<style type="text/css">
td {
text-align: center;
}
</style>
If you have more than one table and only want to do this to a specific table, you can use the selectors to get even more granular.
Use the align
attribute for <td>
.
Using the css style text-align: center;
, either as an inline style (below) or as a css style applied to all <td>
elements (as suggested in Joel's answer).
<td style="text-align:center;">
Table contents here
</td>
This is a solution with only html tags.
<table>
<tr>
<td><center>Data</center></td>
</tr>
</table>
But the other solutions are better in view of best practices
精彩评论