Can't Center tables

Discuss building things with or for the Mozilla Platform.
Post Reply
djg
Posts: 49
Joined: November 25th, 2002, 9:15 am

Can't Center tables

Post by djg »

Hi
Wondering why the tables dont center on this site - www.caperdu.com

The heading and the body should be centered by CSS. They are both in a table of class 'Center'.
The class is:
table.center {
width: 90%;
margin-left: auto;
margin-right: auto;
margin: 0px; /*cellspacing*/
padding: 0px; /*cellpadding*/
border: 0
}

The class seems to be properly set on the tables as changing the width or padding changes the table's layout. but still the content is not centered.
This seems to be the right way to center tables with CSS according to http://www.granneman.com/webdev/coding/ ... erta/index

The page source is here: http://www9.brinkster.com/goodwin/caperdu/
and the css is here: http://www9.brinkster.com/goodwin/caperdu/layout.css

any comments greatfully received!

thx

dave
User avatar
nilson
Posts: 4100
Joined: February 15th, 2003, 11:55 pm
Location: Tuscaloosa, Alabama
Contact:

Post by nilson »

Although ulikely, it could be that the table *is* centered, and the content inside the table is not. You could try temporarily putting a border on the table to see if this is the case, and if it is, put

Code: Select all

text-align: center;


in the table.center class def.

Other than that, I dunno. Hope it helps.
djg
Posts: 49
Joined: November 25th, 2002, 9:15 am

Post by djg »

text-align as you suggest is the flow of the text inside the table cell, which I want to stay left aligned. I'd just like an equal border around my content

thx

dave
bob_seb
Posts: 139
Joined: November 5th, 2002, 11:35 am
Location: Lyon, France
Contact:

Re: Can't Center tables

Post by bob_seb »

djg wrote:

Code: Select all

table.center {
      width: 90%;
      margin-left: auto;
      margin-right: auto;
      margin: 0px; /*cellspacing*/
      padding: 0px; /*cellpadding*/
      border: 0
      }

Code: Select all

margin: 0px;
is equivalent to :

Code: Select all

margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
So, it hides

Code: Select all

margin-left: auto;
margin-right: auto;
To really do a cellspacing of 0, you should be using the border-spacing property.
Unfortunatly, support for this is very bad (according E.Meyer in Eric Meyer on CSS) so you can keep the ugly cellspacing table attribute.
djg
Posts: 49
Joined: November 25th, 2002, 9:15 am

Post by djg »

hey!

You're great! thx. problem solved. I wonder if anyone serously codes sites by hand anymore, or if everyone now uses Dreamweaver. Prehaps it's time I 'upgraded'

thx again

dave
User avatar
nilson
Posts: 4100
Joined: February 15th, 2003, 11:55 pm
Location: Tuscaloosa, Alabama
Contact:

Post by nilson »

djg
Posts: 49
Joined: November 25th, 2002, 9:15 am

Post by djg »

nice site - like the clean design.wish i could show off mine (www.davidgoodwin.net) but something has gone wrong on my server (in nyc) and I'm currently in TX :(

dave
Sander
Posts: 634
Joined: November 5th, 2002, 5:35 am
Location: The Netherlands, when not travelling

Post by Sander »

djg wrote:I wonder if anyone serously codes sites by hand anymore, or if everyone now uses Dreamweaver.
Dreamweaver... *shudders*
I get handed Dreamweaver code from designers at work. Then I manually rip out 90% of that and hand-code it back in taking less than 10% of the space, making it suddenly work in other browsers than IE as well...
The few sites where I can do the design on my own (mostly my own, plus content management systems) are entirely handcoded. There is no other way to get something truly professional.
Post Reply