Center Align a table in XHTML Strict

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

How is it possible to use CSS to center align a table when the doctype is XHTML Strict?

i'v tried:

margin:0px 10% 0px 10%;

margin-top:0;
margin-right:10%;
margin-bottom:0;
margin-left:10%;

putting it inside a DIV and setting the width of the table (in CSS) to 100%; but that does not work in IE :S

Anyone found a solution to this frustrating problem?

Busy's picture

He has: 6,151 posts

Joined: May 2001

there are ways to cheat it, (text-align:center) but you should remember tables in XHTML strict are meant to be for data only
and IE6 among other browsers don't handle all of CSS properly so if it's really important to be centered use XHTML transitional

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

margin: 0 auto 0 auto;

It won't work in IE6 because it still has a broken box model. (STILL!) You should be able to use text-align: center; for IE6. It's been awhile since I had to center something, so I'm not 110% positive - test test test, then check css-discuss.org archives. Wink

dk01's picture

He has: 516 posts

Joined: Mar 2002

Yes body { text-align: center } will work but you should not be using tables for a site in Strict xhtml! You can do the exact same thing with div's!
-dk

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I'm not using it for the design, i'm using it for tablular data - I think ( a table of links is tablular data isn't it?)

But ok, I'll try those, suggestions.

Busy: I'm not using any doctype, this is for my personal site which I develope to learn XHTML and PHP and CSS. Laughing out loud And yeah it does look like I will have to change to XHTML Transitional if it were for someone :S

Busy's picture

He has: 6,151 posts

Joined: May 2001

Not using a DOC type tag, this alone can cause problems on some browsers, as the browser tries to compile your layout in one of two ways - new and old
most troublesome browsers are NS6 and IE6

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Really? Oh, didn't know that Busy thanks Laughing out loud

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.