Table Center (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets and Accessibility



Message


Chugachman -> Table Center (12/26/2004 4:15:29)

What is the correct syntax in CSS so that a table is centered on the page.

Much obliged...happy holidays!




d a v e -> RE: Table Center (12/26/2004 6:06:22)

this
http://members.tiscali.fi/dave_pirjo/test-area/css_stuff/table_centred.htm
basically to centre a block level element such as a table use
margin:0 auto;


it won't work in IE if you use a transitional doctype (then you have to use the center attribute on the table element) but if you're using strcit (x)html it works fine., but that's just cos IE is crap.




Chugachman -> RE: Table Center (12/26/2004 13:03:40)

I'm sorry, I didn't communicate well.

What would I write on a CSS style sheet so that all tables are centered on the page. I can't find it in any of my reference books.

Thanks!




Donkey -> RE: Table Center (12/26/2004 18:49:57)

Use what Dave gave you above as the declaration and table as the selector;

table{margin:0 auto;}




Giomanach -> RE: Table Center (12/26/2004 21:15:35)

quote:

it won't work in IE if you use a transitional doctype (then you have to use the center attribute on the table element) but if you're using strcit (x)html it works fine., but that's just cos IE is crap.

A bit more CSS will solve that bug...

CSS:

html, body{
text-align: center;
}

#page{
margin: 0 auto;
width: 775px;
text-align: center;
}

HTML:

<html>
<head>
<title>Page 1</title>
<link type="text/css" rel="stylesheet" href="01.css">
</head>
<body>
<div id="page">
<table>
....Table coding..rows, cells etc....
</table>
</div>
</body>
</html>

works in all browsers without fail =)




d a v e -> RE: Table Center (12/28/2004 16:09:37)

but you would have to remember to explicitly set any descendants of html, body, #page as left aligned unless you wanted those centred too - probably!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625