View Full Version : How to center a table using html 4.01 strict
harrydb
05-25-2003, 10:13 PM
Can anyone tell me how to center a table in a html 4.01 strict document? It should not be too difficult, but I just can't get it to work in IE and Mozilla at the same time.
Greets, Harry
zoobie
05-25-2003, 11:13 PM
Don't quote me...but I think you put it in a container like a <div> or <p> like so: <div style="text-align:center"><table></table></div> :D
harrydb
05-25-2003, 11:23 PM
Unfortunately, that is exactly what I have right now... :rolleyes: It does work in IE, but not in mozilla.
This is the css-code for the div the table is located in:
div#top {
margin: 0 0 0 0;
padding: 0 0 0 0;
position: absolute;
top: 0px;
width: 100%;
height: 47px;
border: 0px;
text-align: center;
background-image : url(../images/back_top.gif);
background-repeat : repeat-x;}
I posted the website here:
http://harrydb.host.sk/beta/
Harry
zoobie
05-25-2003, 11:56 PM
This works in IE, Mozilla, Opera and Netscape without setting any explicit widths:
div.centered {text-align: center;}
div.centered table {margin: 0 auto; text-align: left;}
<div class="centered"><table>
...
</table>
</div>
To also work in Mac IE 5, the margin setting on this style needs to be in the long form:
div.centered table {margin-left: auto; margin-right:auto; text-align: left;}
Happy code bloat. :D
harrydb
05-26-2003, 12:00 AM
<table style="margin: auto">
did the trick, thanks!!
Harry
zoobie
05-26-2003, 12:22 AM
...along with the div {text-align:center} :p
ronaldb66
05-26-2003, 10:04 AM
Don't you people read each others threads?
http://www.codingforums.com/showthread.php?s=&threadid=20586
zoobie
05-26-2003, 10:20 AM
I like coffee tables, myself. :cool:
brothercake
05-26-2003, 02:16 PM
I like coffee tables too, but I wouldn't dream of building a house out of them :p
harrydb
05-26-2003, 02:28 PM
Originally posted by zoobie
...along with the div {text-align:center} :p
This was not neccesary, however I did left it in my code. Cannot cause any harm :)
Harry.
zoobie
05-26-2003, 06:17 PM
Actually, you need text-align:center for IE...Try it without. :D
harrydb
05-27-2003, 02:30 PM
Originally posted by zoobie
Actually, you need text-align:center for IE...Try it without. :D
In IE6 it worked perfecty without that line. However you have to make sure the width of the div is 100%.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.