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?
From stackoverflow
-
If I remember correctly, it's the text-align property. Or do you mean center the table in the html page?
-
To center the table in the page, use auto left and right margins.
table { margin: 0 auto; } -
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 autoto thetable.However, the
text-alignCSS makes it work for pickier browsers. Specifically,text-align: centerwill center thetable, but since it would have a side effect of also centering each cell's contents, you need to applytext-align: leftto the table to reset that property.
0 comments:
Post a Comment