Re: CSS to center a table?

I have found that nesting tables has produced the centering of the table
effect. This is bad coding however and I would recommend that a better way
of aligning tables independently be found and used. The initial table cell
needs to have something in it, either a blank image that is sized to the
width of your page or some text in order for the nested table to center.

<TABLE border="2">
  <tr>
    <td>hhhhhhhhhhhhhhhhhhhhhhh</td>
  </tr>
  <tr>
    <td style="text-align: center">
      <table border="2">
     <tr>
    <td>test</td>
  </tr>
      </TABLE>
    </TD>
  </tr>
</table>


Sincerely,
Franchesca Havas
McKinney, Texas

----- Original Message -----
From: "Michael D. Crawford (by way of Al Gilman <asgilman@iamdigex.net>)"
<crawford@goingware.com>
To: <www-style@w3.org>
Cc: "Michael D. Crawford" <crawford@goingware.com>; <fahrner@pobox.com>
Sent: Saturday, May 19, 2001 10:30 AM
Subject: CSS to center a table?


> [redirected from www-talk -Al]
>
> 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>
> </table>
>
> 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 Monday, 21 May 2001 09:49:32 UTC