4 replies [Last post]
Anonymous
Anonymous's picture
Guru
calgary,alberta
calgary,alberta

I want to find a way to substitute <table align="center"></table> because it is not part of XHTML 1.0 Strict

So basically, I want to align a <table> element that conforms with the XHTML 1.0 Strict DTD.

I hope someone can help me out here Laughing out loud

KnightWolfJK
KnightWolfJK's picture
Offline
Enthusiast
Washington, DC
Last seen: 12 years 4 weeks ago
Washington, DC
Timezone: GMT-5
Joined: 2003-06-10
Posts: 210
Points: 0

Quick Fix

The quickest solution would to surround your table in div tags like so:
<div align="center"><table>blah</table></div>

Diplomacy is the art of letting someone have your way

Anonymous
Anonymous's picture
Guru

Substitution for &lt;table align=&quot;center&quot;&gt; ?

Too bad that IE doesn't support the correct way of doing it, which would be to set the margins to auto...

Anonymous
Anonymous's picture
Guru

Substitution for &lt;table align=&quot;center&quot;&gt; ?

Quote:
Too bad that IE doesn't support the correct way of doing it, which would be to set the margins to auto...

You can make it work in IE by taking advantage of the incorrect way the property, text-align, works:

<div style="text-align: center;"><table></table></div>

and then use margin: auto; for other browsers:

<div style="text-align: center;"><table style="margin: auto;"></table></div>

Damien
Offline
Regular
Adelaide, South Australia
Last seen: 15 years 45 weeks ago
Adelaide, South Australia
Joined: 2003-09-05
Posts: 16
Points: 0

Substitution for &lt;table align=&quot;center&quot;&gt; ?

This is what I use:

.center {
	text-align: center;
}
.center table {
	margin: auto;
}

<div class="center">
  <table></table>
</div>

This is because MSIE does not conform to "margin: auto" so we use the <div> instead because of the way elements inherit alignments from parent elements in MSIE (which is non-standard as well).