Jack Stevens
Jack Stevens

Reputation: 389

I can't seem to figure out how to center align my table

<table border="0" align="center">
<tbody>
<tr>
<td>Cell1</td>
<td>Cell1</td>
</tr>
<tr>
<td>Cell1</td>
<td>Cell1</td>
</tr>
<tr>
<td>Cell1</td>
<td>Cell1</td>
</tr>
<tr>
<td>Cell1</td>
<td>Cell1</td>
</tr>
</tbody>
</table>

I am not good with coding. I've tried but cannot figure it out. Your help would be greatly appreciated.

Upvotes: 0

Views: 2042

Answers (2)

Dennis Traub
Dennis Traub

Reputation: 51624

// CSS:

#container {
    text-align:center; // needed if you expect IE 5
}

.centered {
    margin:0px auto; // this sets left/right margin to auto and
                     // centers the element
}


// HTML:

<div id="container">
    <table class="centered" border="0">
        ...
    </table>
</div>

Or if you want to style inline:

<div style="text-align:center;">
    <table style="margin:0px auto;" border="0">
        ...
    </table>
</div>

Upvotes: 1

jeff
jeff

Reputation: 4333

Try this:

<div style="width: 100%; text-align: center;">
    <!-- Your table here -->
</div>

Upvotes: 1

Related Questions