Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Centering a table with style sheets in xhtml 1.1

OK, so now I've got my paragraphs justified properly, I want to center my tables.

The tables are inside a div, and the style sheet has "div {text-align:center}" which sets everything in the div to centered, except the tables.

Setting "table {text-align:center}" in the style sheet has no effect.

Of course, I can say align="center" in the table tag, but according to the xhtml validator ( http://validator.w3.org/ ), the align property is deprecated and doing so will make my xhtml invalid.

Any ideas?

Malcolm
Thursday, February 27, 2003

Try this:

div {
    text-align: center;
    align: center;
}

www.marktaw.com
Thursday, February 27, 2003

That works in IE6, but the tables are still left-aligned in Opera.  Maybe I'll check if there are any known issues with this.

Malcolm
Friday, February 28, 2003

1) You should be able to do this:

#CENTERED { text-align:center }

<DIV ID="CENTERED">
<table>
...
</table>
</DIV>

2) If this does not work, you can always use brute force (the old way):

<table width="100%">
<tr>
<td align="center" width="100%">
  <table>
  ...
  </table>
</td>
</tr>
</table>

Joel Finkel
Friday, February 28, 2003

*  Recent Topics

*  Fog Creek Home