【问题标题】:Centering a table in Firefox在 Firefox 中将表格居中
【发布时间】:2011-04-06 21:58:37
【问题描述】:

我的一个页面上有一个小表格,我希望它居中,所以编码了<table cellpadding="0" cellspacing="0" align="center">,它在 IE 中运行良好,但在 Firefox 中表格仍然左对齐。

如果我使用 text-align:center n align:-moz-center它在 IE 中不工作

我需要改变什么才能让表格在 Firefox 中居中?如果我应该使用-moz-center 如何让它在 IE 中工作?

我被困在这里了。

【问题讨论】:

    标签: html css html-table alignment


    【解决方案1】:

    margin: auto; 添加到表中。这是执行此操作的标准方法。

    【讨论】:

      【解决方案2】:

      正如 Lekensteyn 提到的,这里有一些代码来展示它的实际效果:

      <div style="margin: 0 auto; text-align:center;">
      <table border="1" style="width:200px;">
      <tr>
        <td>Hello</td>
        <td>How</td>
      </tr>
      <tr>
        <td>are</td>
        <td>you?</td>
      </tr>
      </table>
      </div>
      

      它应该基于 widthmargin 样式定义来居中。

      【讨论】:

      • 这将不起作用,除非 div 具有设置的宽度。默认情况下,块级元素的宽度为 100%。
      猜你喜欢
      • 2016-07-16
      • 2012-11-18
      • 2012-12-14
      • 2016-09-12
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      相关资源
      最近更新 更多