Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Centering tables with CSS

0 views
Skip to first unread message

Enrique Fowler Newton

unread,
Mar 29, 1999, 3:00:00 AM3/29/99
to
I want tables to appear in the middle of the sheet.

In my style sheet, I defined: TABLE { width: 95% ; margin-left: 0.5em ;
border-style: solid ; border-width : 0.1em }

If I use <TABLE>...</TABLE>, the table appears in the left (both in Explorer
4.01 and Netscape 4.5).

If I use
<CENTER><TABLE>...</TABLE></CENTER> or
<DIV align="center"><TABLE>...</TABLE></DIV>,
the table appears:
in the center using Explorer and
in the left using Netscape.

I know that CENTER is deprecated in HTML 4.0.

I couldn't find the CSS attribute to center the table.

Any suggestion or comment will be appreciated.

Enrique Fowler Newton
Buenos Aires
Argentina
http://usuarios.inea.com.ar/~fowler

Daibhidh

unread,
Mar 29, 1999, 3:00:00 AM3/29/99
to

Enrique Fowler Newton wrote in message <92272246...@news.remarQ.com>...

>In my style sheet, I defined: TABLE { width: 95% ; margin-left: 0.5em ;
>border-style: solid ; border-width : 0.1em }
>
>...

>I couldn't find the CSS attribute to center the table.

If you have margin-left defined on the table you won't get a centered table,
because the way to center in CSS is to set the margins to 'auto':

TABLE { width: 95% ; margin-left: auto; margin-right: auto;
border-style: solid ; border-width : 0.1em }

Whether any of the pissant crop of fuzzila browsers implement this correctly
is another matter. IE4 doesn't, even though it's pretty clear in the CSS1
spec.

You could try this declaration:

CENTER { text-align: center }

then put your table inside <CENTER>...</CENTER> and see what happens.

But since you want the table width to be 95%, why not just forget the width
and specify 2.5% margins?

TABLE { margin-left: 2.5%; margin-right: 2.5%; width: auto;
border-style: solid ; border-width : 0.1em }

? 'Course, support for the border is pretty strange in IE4. Make sure you
override any contrary attribute declarations in the HTML tags. For example,
if you have "width=" in your table cells and those widths don't add up to a
95% wide table you'll have a problem. You can override by declaring width
for TD in the stylesheet. For differing widths use classes.

Daibhidh


Kristian V. Jensen

unread,
Mar 30, 1999, 3:00:00 AM3/30/99
to
Try this:

<TABLE align="left".........

It works for me and always has.

Kristian V Jensen
webha...@net4you.dk

Kristian V. Jensen

unread,
Mar 30, 1999, 3:00:00 AM3/30/99
to
Sorry, panic andd confusion reigned my head. I meant:
<TABLE align="center".........

Kristian V Jensen
webha...@net4you.dk


Adam J. Langer

unread,
Mar 30, 1999, 3:00:00 AM3/30/99
to
Enrique Fowler Newton <fow...@inea.com.ar> wrote in message
news:92272246...@news.remarQ.com...

> I want tables to appear in the middle of the sheet.

I just did this the other day. Try this:

<DIV STYLE="text-align: center"><TABLE>your table stuff here</TABLE></DIV>

Adam Langer

http://www.cvm.okstate.edu/~users/langera/


Enrique Fowler Newton

unread,
Mar 31, 1999, 3:00:00 AM3/31/99
to
Tranks to everybody.

I read your suggestions and also visited
http://developer.netscape.com/support/bugs/known/css.html, where I read:
"You cannot assign most styles to the <TABLE> or <TR> elements. Use the <TD>
element instead. Exceptions are background image and color on the <TABLE>
tag. For other styles, results may vary depending on the complexity of the
table and their use is not recommended."

After making some tests, I decided:
- To remove { width: 95% ; margin-left: 0.5em } from the TABLE style.
- To add the deprecated <...align="center"> to <TABLE>.

But the table still appeared in the center using Explorer and in the left
using Netscape.

Then, I decided to change from implicit to explicit widths of columns. This
means: to add
<COLGROUP> and <COL width="x%"> and to remove widht="x%> from <TD
width="x%">

This, in spite of this message of CSE HTML Validator v3.05 "COL and COLGROUP
are currently only supported by Internet Explorer. For instance, Netscape
4.0 does not support these elements".

After adding <COLGROUP> and <COL...> my tables began to center in Netscape
4.5.

Please, don't ask me why.

A little problem remains: Netscape doesn't recognize the width of the table.
I can live with it.

--------------------

Enrique Fowler Newton escribió en mensaje
<92272246...@news.remarQ.com>...


|I want tables to appear in the middle of the sheet.
|

|In my style sheet, I defined: TABLE { width: 95% ; margin-left: 0.5em ;
|border-style: solid ; border-width : 0.1em }
|

|If I use <TABLE>...</TABLE>, the table appears in the left (both in
Explorer
|4.01 and Netscape 4.5).
|
|If I use
| <CENTER><TABLE>...</TABLE></CENTER> or
| <DIV align="center"><TABLE>...</TABLE></DIV>,
|the table appears:
| in the center using Explorer and
| in the left using Netscape.
|
|I know that CENTER is deprecated in HTML 4.0.
|

|I couldn't find the CSS attribute to center the table.
|

Timothy Arnold

unread,
Apr 2, 1999, 3:00:00 AM4/2/99
to
or even:

<DIV ALIGN=center><TABLE>your table stuff here</TABLE></DIV>

not CSS, but it works for me.

Timothy D. Arnold
tar...@one.net


Adam J. Langer <lan...@okstate.edu> wrote in message
news:7drerl$6...@news.okstate...


> Enrique Fowler Newton <fow...@inea.com.ar> wrote in message
> news:92272246...@news.remarQ.com...

> > I want tables to appear in the middle of the sheet.
>

The ByteMystro

unread,
Apr 3, 1999, 3:00:00 AM4/3/99
to
Have you tried

<center><table>Text stuff</table><center>

This is what use and it works both in IE and NN. And validates.

Enrique Fowler Newton wrote:
>
> After making some tests, I decided:
> - To remove { width: 95% ; margin-left: 0.5em } from the TABLE style.
> - To add the deprecated <...align="center"> to <TABLE>.
>
> But the table still appeared in the center using Explorer and in the left
> using Netscape.
>

--
The ByteMystro
The MerchantStore - Web Site Design Links
http://www.merchantstore.com

Enrique Fowler Newton

unread,
Apr 3, 1999, 3:00:00 AM4/3/99
to
<CENTER> is what I used until I decided to change to HTML 4.0+CSS1.
It worked but I dropped it because it's "deprecated" in HTML 4.0.

--


Enrique Fowler Newton
Buenos Aires
Argentina
http://usuarios.inea.com.ar/~fowler

The ByteMystro escribió en mensaje <370579BC...@merchantstore.com>...

0 new messages