代码之家  ›  专栏  ›  技术社区  ›  LearnProgramming

bootstrap table,如何平均对齐每个<td>?

  •  1
  • LearnProgramming  · 技术社区  · 6 年前

    正如你在下面的图片中看到的,红线代表了每一条的宽度不等。 <td> . 我的目标是制造每一个 <TD & GT; 均匀对齐。我该怎么做?

    CSS

    .stickyFooter {
                background: #c1c1c1;
                position: fixed;
                left: 0;
                right: 0;
                bottom: 0;
                height: 50px;
                font-size: 13px;
            }
    

    代码

    <div class="stickyFooter wrap visible-sm visible-xs table-responsive" style="margin-bottom: 0px; border: none;">
    <table class="table">
        <tr align="center">
            <td><a href="#"><i class="fa fa-home fa-2x"></i><br>Home</a></td>
            <td><a href="#"><i class="fa fa-bell fa-2x"></i><br>Notification</a></td>
            <td><a href="#"><i class="fa fa-file-invoice-dollar fa-2x"></i><br>Transaction</a></td>
            <td><a href="#"><i class="fa fa-search fa-2x"></i><br>Directory</a></td>
            <td><a href="#"><i class="fa fa-newspaper fa-2x"></i><br>Ads</a></td>
            <td><a href="#"><i class="fa fa-dollar-sign fa-2x"></i><br>Billing</a></td>
            <td><a href="#"><i class="fa fa-plus fa-2x"></i><br>More</a></td>
            <td><a href="#"><i class="fa fa-cogs fa-2x"></i><br>Setting</a></td>
        </tr>
    </table>
    

    图像

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  3
  •   Obsidian Age    6 年前

    额外的宽度很可能来自您在那里的fontAwesome图标,默认情况下,这些图标具有不同的宽度。这可以通过应用类来纠正 fa-fw 到每个图标:

    td {
      border: 1px solid black;
      min-width: 200px;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <link href="https://use.fontawesome.com/releases/v5.0.7/css/all.css" rel="stylesheet" />
    
    
    <div class="stickyFooter wrap visible-sm visible-xs table-responsive" style="margin-bottom: 0px; border: none;">
      <table class="table">
        <tr align="center">
          <td><a href="#"><i class="fa fa-fw fa-home fa-2x"></i><br>Home</a></td>
          <td><a href="#"><i class="fa fa-fw fa-bell fa-2x"></i><br>Notification</a></td>
          <td><a href="#"><i class="fa fa-fw fa-file-invoice-dollar fa-2x"></i><br>Transaction</a></td>
          <td><a href="#"><i class="fa fa-fw fa-search fa-2x"></i><br>Directory</a></td>
          <td><a href="#"><i class="fa fa-fw fa-newspaper fa-2x"></i><br>Ads</a></td>
          <td><a href="#"><i class="fa fa-fw fa-dollar-sign fa-2x"></i><br>Billing</a></td>
          <td><a href="#"><i class="fa fa-fw fa-plus fa-2x"></i><br>More</a></td>
          <td><a href="#"><i class="fa fa-fw fa-cogs fa-2x"></i><br>Setting</a></td>
        </tr>
      </table>
    </div>

    记住 <td> 单元格将自动展开以填充其可用宽度 <tr> 容器和文本较长的单元格将“希望”在这方面占用更多空间。如果要强制约束(或展开)它们,只需为它们定义 width .

    这也可以在上面的示例中看到,其中我声明 必须 至少是 200px 每个都很宽。