简体   繁体   中英

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.

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM