html - 水平对齐表格

标签 html css bootstrap-4

我有这张 table ,但我无法将它们水平并排放置,我尝试了很多东西,但我显然遗漏了一些东西,你会推荐什么?我正在为那些专栏而苦苦挣扎。

更新: 我有 7 个表,它们确实有 3 列,但行数彼此不同。 我正在使用主题 Bootstrap v4。每当我执行 class="table" 时,它都会出错。

enter image description here

<div class="table">

<table class="table-striped" style="display: inline-block; float: left; ">
  <thead>
    <tr>
      <th style="width:200px;"> Module </th>
      <th style="width:120px;"> Info </th>
      <th> Value </th>
    </tr>
  </thead>
  <tbody>


<tr>
<td> ACU  </td>                 
<td> Fls </td>             
<td> 0</td> </tr>
<tr>
<td>  Mode</td>                    
<td> Trk</td>              
<td> 3</td> 
</tr>
<tr>
<td>  Use</td>                 
<td> PS</td>          
<td> 43</td> 
</tr>

  </tbody>
</table>




<table class="table-striped" style="display: inline-block; margin-left:150px;">
  <thead>
    <tr>
      <th style="width:200px;">  Module </th>
      <th style="width:120px;"> Info </th>>
      <th> Value </th>
    </tr>
  </thead>
  <tbody>
    <tag2>
        <tr>
        <td> PBit</td>          
         <td> Lock</td>    
         <td> 1</td> 
         </tr>
        <tr><td> Bit</td>         
          <td> NA</td>       
          <td> 0</td> 
          </tr>
        <tr>
        <td> it</td>          
         <td> Lock</td>    
         <td> 1</td>
         </tr>
        <tr>
        <td> Bit</td>         
          <td> NA</td>      
          <td> 0</td> 
          </tr>
        <tr>
        <td> Bit</td>         
        <td> Lock</td>    
         <td> 1</td>
         </tr>
        <tr>
        <td> Bit</td>         
        <td> NA</td>       
        <td> 0</td> 
        </tr>

  </tbody>
</table>

最佳答案

我添加了额外的 merge_table div,将您的两个表包裹在其中,这样,在我可以使用 flexbox 并排获取表之后。

我使用了 d-flex 类,代表 display: flex 并且为了区分两个表我添加了 ml-3 代表 margin-left.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<div class="merge_table d-flex">
    <table class="border">
        <thead>
            <tr>
                <th> Module </th>
                <th> Info </th>
                <th> Value </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td> Mode</td>                    
                <td> Track</td>             
                <td> 3</td> 
            </tr>
            <tr>
                <td> A</td>               
                <td> PS</td>          
                <td> 43</td>
            </tr>
        </tbody>
    </table>

    <table class="border ml-3">
        <thead>
            <tr>
                <th> Module </th>
                <th> Info </th>
                <th> Value </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td> Mode</td>                    
                <td> Track</td>             
                <td> 3</td> 
            </tr>
            <tr>
                <td> A</td>               
                <td> PS</td>          
                <td> 43</td>
            </tr>
        </tbody>
    </table>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

关于html - 水平对齐表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56605363/

相关文章:

html - 导航栏未显示所有标题

html - 从 Silverlight 添加 innerHTML 不会应用样式

javascript - jQuery 联系表单标题移动效果

html - 如何卸载 iframe 直到显示

CSS:iframe 不显示 100% 高度...更像是 100px 高度

javascript - 快速滚动离开悬停触发的弹出窗口不会隐藏弹出窗口

css - 无法处理引导 css

javascript - 选择带有 DOM 的 div 内容,但没有子元素

css - Bootstrap FormGroup/Input 仅在 IOS 中不完全可见(被某些层隐藏了一半)

javascript - 在服务器上部署 React App 时 MIME 类型检查失败