html - table 根本不居中

标签 html css html-table center

我知道这个问题已被问过十亿次,但我查看了解决方案,但表格只是拒绝居中。我希望有人能帮助我。

这是我对 HTML 的看法:

<div id="paccount">
    <table style="margin: 0 auto;">
        <tr>
            <td width="320" height="150">Order History</td>
            <td width="28" rowspan="4"></td>
            <td width="320" rowspan="4">Personal Information</td>
        </tr>
        <tr>
            <td height="15"></td>
        </tr>
        <tr>
            <td width="320" height="90">Preferences</td>
        </tr>
        <tr>
            <td height="15"></td>
        </tr>
        <tr>
            <td height="115" colspan="3">Logout</td>
        </tr>
    </table>
</div>

这是该 div 的 CSS:

#paccount {
    width: 668px;
    height: 400px;
    background-color: transparent;
    text-align:center;  
}

编辑:对不起,我的意思是将文本居中放置在表格中。

最佳答案

您没有将表格居中。

您正试图将所有文本居中。

您必须先将 #paccount div 居中。

这样做:

#paccount{
    width:668px;
    height:400px;
    background-color: transparent;
    margin:0 auto; /* Here is the key! */
}

关于html - table 根本不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23883483/

相关文章:

javascript - $.ajax 引用错误 : data is not defined

html - 如何在图像下传递文本,其中 2 列在图像的 Bootstrap 中定义,另一列用于文本?

html - 水平展开表格

javascript - 单击表格内的输入时从 html 表格获取 id

html - 表格的小问题

php - 在 X-Editable 中通过 Ajax 提交数据

html - 使用 flexbox 将子元素聚集在 div 的底部

css - Thymeleaf 装饰器 - 如何通过特定页面上的自定义页脚替换布局中的页脚

html - 保持一个元素而不是整行的中心对齐

javascript - 单击按钮时如何显示 hr