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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.