

CSS to center a table?

From: Michael D. Crawford <crawford@goingware.com>
Date: Sat, 19 May 2001 02:12:05 -0400
Message-ID: <3B060EB5.7070500@goingware.com>
To: www-talk@w3.org
Is there a way to use cascading stylesheets to center a table 
horizontally on a page?

I can give offsets in absolute values or percentages from the left or 
right, but my tables have different widths.  I'd like each table in my 
page to be centered no matter how wide or narrow it may be, using the 
same class for such tables.

What happens when I try using text-align on the table is that the text 
in the tables cells is centered within the cells.  I want the cell text 
to be left justified but for the table to be centered as a whole.

(Actually, checking other browsers, in Netscape 4.73 on Linux nothing
happens, and Mozilla 0.9 on the Mac I get the behaviour I describe.  I
can't get Netscape on the Mac to pick up stylesheets from a linked file.
Internet Explorer 4.01 on the Mac does what I want.  What's the deal?)

Here's my first attempt:

In article.css:

<!-- My CSS
table.center {text-align: center}

in my article:

<table class="center">
<tr><td>Some Text</td></tr>
<tr><td>Some Longer Text</td></tr>

This comes out like the following, with the text centered in the cells:

    Some Text
Some Longer Text

What I want is the following, with the text left-justified in the cells 
but the whole table centered:

                              Some Text
                              Some Longer Text
Received on Saturday, 19 May 2001 02:11:14 GMT
