Center Align Table Using CSS

Hi,
I have to center align a table using CSS and tried a few different methods, here is the current code:

.new-table, th, td {
   background-color: #000000;
   color: #ffffff;
}

Any suggestions would be much appreciated.

Thanks!
canuWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
Try this:
table.new-table {
    margin-left: auto;
    margin-right: auto;
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Naitik GamitSoftware DeveloperCommented:
Look at this different methods to Center Align Table Using CSS :

http://www.granneman.com/webdev/coding/css/centertables/

Hope this will help you.
canuWebmasterAuthor Commented:
Hi zc2 & Naitik,

Thanks for getting back to me so quickly.

I tried your suggestions and have the following to report:

Method 1
margin-left: auto;
margin-right: auto;

This unfortunately didn't center the table.

Method 2
width:70%;  
margin-left:15%;    
margin-right:15%;

Table centered correctly but the column widths were changed significantly.

Didn't use Method 3 because the website is responsive so a fixed width table isn't suitable.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

zc2Commented:
post your HTML+CSS may be?
canuWebmasterAuthor Commented:
Here's the CSS again:

.new-table, th, td {
   background-color: #000000;
   color: #ffffff;
}

and here's the HTML:
<table class="new-table">
<tbody>
<tr>
<th>Header1</th>
<th>Header2</th>
<th>Header3</th>
</tr>
<tr>
<td data-th="Header1"><a href="https://www.website1.com">Link1</a></td>
<td data-th="Header2"><a href="https://www.website2.com">Link2</a></td>
<td data-th="Header3"><a href="https://www.website3.com">Link3</a></td>
</tr>
<tr>
<td data-th="Header1"><a href="https://www.website4.com">Link4</a></td>
<td data-th="Header2"><a href="https://www.website5.com">Link5</a></td>
<td data-th="Header3"><a href="https://www.website6.com">Link6</a></td>
</tr>
<tr>
<td data-th="Header1"><a href="https://www.website7.com">Link7</a></td>
<td data-th="Header2"><a href="https://www.website8.com">Link8</a></td>
<td data-th="Header3"><a href="https://www.website9.com">Link9</a></td>
</tr>
</tbody>
</table>

I forgot to mention that this is in a WordPress website, I don't know if that makes any difference or not.

Thanks again....
zc2Commented:
Probably, there are some additional HTML elements which prevent it from the desired result.
The code you sent works perfectly:
http://jsfiddle.net/zqdk4zkq/
canuWebmasterAuthor Commented:
Thanks zc2, the plot thickens.

This is being implemented in a WordPress website, I will try and find out if this is a reason for this not working correctly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.