HTML 居中对齐 Div 中的表格与下面的按钮列表对齐



我想在div中间的顶部将多个表格彼此相邻对齐。 在这些表格下面,我想有一个垂直按钮列表左对齐。我尝试了许多不同的技术,但似乎都没有奏效。请有人帮忙吗?

当前小提琴示例:

https://jsfiddle.net/Jaron787/gg30jgh5/

.CSS

.TSS {
  font-family: Verdana, Geneva, sans-serif;
  font-size: 10.6px;
  font-style: normal;
  text-decoration: none;
  float: left;
  padding-top: 10px;
  padding-right: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  border: 1px solid black;
}
.button {
  background-color: #4CAF50;
  /* Green */
  border: none;
  color: white;
  padding: 5px 15px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  -webkit-transition-duration: 0.4s;
  /* Safari */
  transition-duration: 0.4s;
  cursor: pointer;
}
.button1 {
  background-color: white;
  color: black;
  border: 2px solid #4CAF50;
}
.button1:hover {
  background-color: #4CAF50;
  color: white;
}

.HTML

<div id="lse" class="display">
  <table id="tblData" class="TSS">
    <tr>
      <td align="center" colspan="4"><b>Table 1</b></td>
    </tr>
  </table>
  <table id="tblData" class="TSS">
    <tr>
      <td align="center" colspan="4"><b>Table 2</b></td>
    </tr>
  </table>
  <input type="submit" class="button button1" name="submitButton" value="Button 1">
  <input type="submit" class="button button1" name="submitButton" value="Button 2">
  <input type="submit" class="button button1" name="submitButton" value="Button 3">
  <input type="submit" class="button button1" name="submitButton" value="Button 4">
</div>

可能只是在表周围创建一个包装器。

<div id="centertbl">
<table id="tblData" class="TSS">
  <tr>
    <td align="center" colspan="4"><b>Table 1</b></td>
  </tr>
</table>
<table id="tblData" class="TSS">
  <tr>
    <td align="center" colspan="4"><b>Table 2</b></td>
  </tr>
</table>

然后将文本对齐方式应用于居中。

#centertbl { text-align: center;}

这将使桌子居中。已从类.TSS中删除margin: 0 auto;

将按钮 css 代码从display: inline-block;更改为display: block;

js小提琴 : https://jsfiddle.net/gg30jgh5/6/

我认为你需要这种类型的css:

please check updeted fiddle link:
some changes in your html structure.table is one div and button is another sepreate div.

https://jsfiddle.net/gg30jgh5/9/

将两个表格都设置在一个div 内,并为此div 设置左边距:50%设置div内的所有按钮,并为此div设置clear:both。

最新更新