Page 1 of 1

Centring tables using CSS

Posted: Thu Sep 19, 2002 10:59 am
by f1nutter
I suppose it's about time that all my pages meet HTML 4.01 standard, before learning XHTML or XML. I notice on W3C that the <center> tag and align attribute in <table> are depricated. I guess I need to do it using style sheets. So, how do I centre a table this way?

Thanks.

Posted: Thu Sep 19, 2002 11:44 am
by Takuma
You can't, use

Code: Select all

<div align="center"></div>

Posted: Fri Sep 20, 2002 1:36 am
by twigletmac
To do the same thing using CSS:

Code: Select all

<div style="text-align: center;">Insert table here</div>
or set up a class in your stylesheet

Code: Select all

.aligncenter &#123;text-align: center;&#125;
and use that

Code: Select all

<div class="aligncenter">Insert table here</div>
Never say never Takuma :wink:

Mac

Posted: Fri Oct 04, 2002 10:22 am
by CodeEye
your content is suposed to be separate from your style that is the reason why they removed the center tags

Posted: Sun Oct 06, 2002 2:18 pm
by MattF
This may be of some help:

Code: Select all

table &#123;
    align: center;
&#125;
But it will obvoisly just align all tables on the page.

Posted: Sun Oct 06, 2002 2:26 pm
by twigletmac
First of all in CSS it should be:

Code: Select all

text-align: center;
not

Code: Select all

align: center;
and secondly you can't align your tables like that, you need to put them in divs if you want to align them on the page.

Mac

Posted: Sun Oct 06, 2002 2:36 pm
by MattF
Thanks for staightening me out there, it's usally hit and miss for me and CSS but I thought I'd got that one right :?

I'll remember that in future :D

Posted: Sun Oct 06, 2002 2:39 pm
by twigletmac
Sorry was a bit short before (very tired) but CSS can be a bit tricky.

Mac

Posted: Mon Oct 07, 2002 1:36 am
by Takuma
Why do you think this doesn't work?

Code: Select all

<!-- TABLE STUFF -->
<td style="text-align: center;">Hello</td>
<!-- TABLE STUFF -->

Posted: Mon Oct 07, 2002 1:52 am
by twigletmac
Um, that does work who said it didn't?

Mac

Posted: Mon Oct 07, 2002 5:53 am
by Coco
i never had any trouble with <table align=center>
but i am preferring to use <div> now because i can control everything :P