【发布时间】:2016-10-27 21:44:04
【问题描述】:
我正在尝试在 bootstrap v4 中将图标放置在表格的单元格中(右侧和左侧)。
为此,我以这种方式使用了绝对定位:
HTML
<div class="container">
<div class="table-responsive">
<table id="one" class="table table-bordered table-sm">
<thead>
<tr>
<th class="text-xs-right">
Left Icon Position<span class="left-icon-pos"><i class="fa fa-sort" aria-hidden="true"></i></span>
</th>
<th>
Right Icon Position<span class="right-icon-pos"><i class="fa fa-sort" aria-hidden="true"></i></span>
</th>
</tr>
</thead>
</table>
</div>
</div>
CSS
th {
white-space: nowrap;
position: relative;
}
.right-icon-pos {
position: absolute;
right: 5px;
}
.left-icon-pos {
position: absolute;
left: 5px;
}
这个解决方案效果很好,但是我在调整窗口大小时遇到问题,定位的图标绝对不占用空间并显示在文本上方。
如何获得相同的效果,以便在调整窗口大小时图标与文本并排显示?
欢迎所有解决方案(即使不使用绝对定位)。
谢谢
【问题讨论】:
-
float图标而不是绝对定位它们 -
分别向左侧
th和右侧th元素添加一些padding-left和padding-right -
@JacobGray - 浮动图标不与文本水平对齐
-
@tmg - 这可能是一个很好的解决方案。谢谢
标签: css twitter-bootstrap twitter-bootstrap-4