BinaryBird Posted January 21, 2009 Share Posted January 21, 2009 Hi, i am having trouble trying to center a table. Here is the html and css code: <div id="maintable"> <table> <tr> <td> No of visitors: </td> <td> <?php include( "./counter/counter.php" ); ?> </td> </tr> </table> </div> CSS code : #maintable { text-align:center; } #maintable table.center { margin-left:auto; margin-right:auto; } What am i doing wrong here? I am new to css and html. Please help me. Thanks. Quote Link to comment Share on other sites More sharing options...
zed420 Posted January 21, 2009 Share Posted January 21, 2009 I've just checked it it is in middle. Quote Link to comment Share on other sites More sharing options...
BinaryBird Posted January 21, 2009 Author Share Posted January 21, 2009 I've just checked it it is in middle. It is working in IE 7 but not in firefox. Is there anything that i could be doing wrong? Quote Link to comment Share on other sites More sharing options...
lostprophetpunk Posted January 21, 2009 Share Posted January 21, 2009 Why not just do... <table align='center'> That should work instead of a div around the table. Quote Link to comment Share on other sites More sharing options...
haku Posted January 22, 2009 Share Posted January 22, 2009 Don't use that - the align tag has been deprecated. Are you trying to center the table, or center the contents of the table? Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted January 23, 2009 Share Posted January 23, 2009 Hi, i am having trouble trying to center a table. Here is the html and css code: [code] <div id="maintable"> <table> <tr> <td> No of visitors: </td> <td> <?php include( "./counter/counter.php" ); ?> </td> </tr> </table> </div> CSS code : #maintable { text-align:center; } #maintable table { width: SPECIFY ABSOLUTE WIDTH px; margin: 0 auto; } I edited the code for you. To center the table you must specify an abosolute width and then margin: 0 auto; it. If you want to center the contents of the table then you can use text-align: center; for text and if you want to center images and other block elements, you'll need to use some advanced css. I hope this works for you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.