【问题标题】:Center align table as a whole in the middle of the page with HTML [duplicate]使用 HTML 在页面中间将整个表格居中对齐 [重复]
【发布时间】:2017-07-11 21:24:10
【问题描述】:

用 HTML 将整个表格置于页面中间的最简单方法是什么?

【问题讨论】:

    标签: html alignment center


    【解决方案1】:

    使用以下 CSS:

    table {
        margin: 0 auto;
    }
    

    【讨论】:

      【解决方案2】:

      你不能只使用HTML

      <center> 是唯一可以做到这一点的元素,但不是首选元素,并且已弃用

      因此您可以为此使用CSS。 只需将父元素的位置设置为relative,并将该元素的水平边距设置为auto

      示例:

      <div id="parent">
          <table>
              ....
          </table>
      </div>
      
      #parent {
          position: relative;
      }
      table {
          margin: 0px auto;
      }
      

      【讨论】:

      • #parent {position: relative;} 是不必要的。 px0 之后也是如此。
      猜你喜欢
      • 1970-01-01
      • 2012-12-13
      • 2018-12-02
      • 2021-10-27
      • 2011-02-11
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      相关资源
      最近更新 更多