View Full Version : centering table with CSS?


fruitcake
09-22-2003, 09:55 AM
How can I center my table, using CSS? I'm doing XHTML, and so have to have the external style sheet, and no formating in the .htm file.
You must be able to do it, but I can't figure it out.

MaGiCSuN
09-22-2003, 05:35 PM
put the following between your <head> and </head>

<style type="text/css">
<!--
#table1 {margin-left: auto; margin-right: auto; text-align: center;}

#td1 {text-align: left;}
-->
</style>

then put in your <table>:

id="table1"

and in your <td> tag:

id="td1"

if it's the only table you use on that page you can also just use table and then you will not have to use ID or CLASS. so your css will be:

<style type="text/css">
<!--
table {margin-left: auto; margin-right: auto; text-align: center;}

td {text-align: left;}
-->
</style>

fruitcake
09-23-2003, 12:20 AM
it doesn't work in IE, is there a way so it works there as well?

pb&j
09-23-2003, 03:46 AM
css...
.centerit {text-align:center;}

coding...
<div class="centerit">
table coding or whatever here.
</div>