如下图所示,红线代表每个<td>
的宽度不相等。我的目标是使每个<td>
均匀对齐。我该怎么办?
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>
图片
答案 0 :(得分:3)
额外的宽度可能来自您那里的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
宽。