Jump to content

Alligning a table to the center


BinaryBird

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/141756-alligning-a-table-to-the-center/
Share on other sites

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!  :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.