I have a table in html. I prefer to layout the table centered. What is the css style for this layout? And any online css tools to interactively see the style change?
A:
If I remember correctly, it's the text-align property. Or do you mean center the table in the html page?
evilpenguin
2009-03-27 22:09:45
A:
To center the table in the page, use auto left and right margins.
table {
margin: 0 auto;
}
Bryson
2009-03-27 22:12:48
+3
A:
Given this HTML:
<div>
<table>
<!-- contents -->
</table>
</div>
You can use this CSS:
div{
margin:0 auto;
text-align:center;
}
div table{
margin:0 auto;
text-align:left;
}
Most browsers will already work if you apply margin: 0 auto
to the table
.
However, the text-align
CSS makes it work for pickier browsers. Specifically, text-align: center
will center the table
, but since it would have a side effect of also centering each cell's contents, you need to apply text-align: left
to the table to reset that property.
Ron DeVera
2009-03-27 22:16:58