【问题标题】:I can't seem to figure out how to center align my table我似乎无法弄清楚如何居中对齐我的桌子
【发布时间】:2011-11-28 17:51:23
【问题描述】:
<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>

我不擅长编码。我已经尝试过,但无法弄清楚。非常感谢您的帮助。

【问题讨论】:

    标签: html-table alignment center


    【解决方案1】:
    // 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>
    

    或者如果你想内联样式:

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

    【讨论】:

    • 不客气。请不要犹豫,将此标记为已回答。
    【解决方案2】:

    试试这个:

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

    【讨论】:

    • 谢谢,但没用。我正在使用wordpress。我输入代码,表格位于管理区域的中心。但是当我去站点刷新页面时,表格仍然在页面的左侧。
    • @JackStevens 看起来这对您的问题很有帮助。
    • 也感谢您的帮助杰夫。丹尼斯的风格内联建议效果很好。谢谢。
    猜你喜欢
    • 2021-06-04
    • 1970-01-01
    • 2020-11-14
    • 2011-07-08
    • 2014-05-19
    • 2023-02-11
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多