clarity
clarity

Reputation: 431

center aligning a table

how do you center align a table in the middle of the page using css. This is what I have http://jsfiddle.net/m5uEr/

<div style="text-align: center; border-style:solid;">
    <table style="border-style:solid;">
        <tr>
            <td>test</td>
        </tr>
    </table>
</div>

Upvotes: 0

Views: 129

Answers (4)

mr mojo risin
mr mojo risin

Reputation: 555

Did you put margin-left:auto, margin-right:auto in the properties of the div?

That is easy to do.

Those properties should belong in table

<div style="text-align: center; border-style:solid;">
    <table style="border-style:solid; margin-left:auto; margin-right:auto; ">
        <tr>
            <td>tdddest</td>
        </tr>
    </table>
</div>​

Upvotes: 1

clarity
clarity

Reputation: 431

css wasn't working so I did a <table align="center">

this is on IE8

Upvotes: 1

jordan
jordan

Reputation: 10722

Set a width on your table and set

margin:auto

Upvotes: 1

gdoron
gdoron

Reputation: 150253

table.center {
    margin-left:auto; 
    margin-right:auto;
  }

<table style="border-style:solid;" class="center">
    <tr>
        <td>test</td>
    </tr>
</table>

Your updated fiddle

Google found it for me with this text: "center align table css"

Upvotes: 2

Related Questions