【问题标题】:HTML5 How to align a table to center inside a form?HTML5如何将表格对齐到表格内的中心?
【发布时间】:2014-12-30 09:38:20
【问题描述】:

我有一个<form>,在该表单中,我有一个<table>。我尝试在该表单上使用text-align: centeralign-items:center,但其中的表格仍然与左侧对齐(而表格的子元素与该表格内的中心对齐)。如何在表格内将表格居中对齐?

【问题讨论】:

标签: css html alignment text-align


【解决方案1】:

当你想在父级的中心位置对齐表格时,只需使用:

css:

margin: 0 auto;

示例:

html:

<form >
 <table>

 </table>
</form>

css:

form {
  width:80%; 
  height: 200px; 
  background-color: black;
}

table {
   margin: 0 auto;
   z-index: 1;
   width:50%; 
   height: 50px; 
   background-color: red;
}

http://jsfiddle.net/bvo7v7f9/

【讨论】:

    猜你喜欢
    • 2017-08-03
    • 2013-11-27
    • 2015-06-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 2016-02-12
    • 2020-03-31
    • 1970-01-01
    相关资源
    最近更新 更多