navs
不是navbar
https://getbootstrap.com/docs/4.1/components/navs/#vertical
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link A
<span class="badge badge-warning badge-pill">140</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link B
<span class="badge badge-warning badge-pill">300</span>
</a>
</li>
</ul>
轮胎变化
<span class="badge badge-warning badge-pill">
到
<span class="badge badge-warning badge-pill ml-auto">
但是没用
编辑:请参见下面的@Temani Afif答案
如果仅使用d-flex
使用d-flex align-items-center
解决了问题
答案 0 :(得分:1)
您需要使a
元素成为flex容器,才能使用ml-auto
/ mr-auto
。只需将d-flex
添加到a
:
我还添加了align-items-center
居中,但这不是强制性的:
.nav {
background:pink;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" >
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link d-flex align-items-center" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link A
<span class="badge badge-warning badge-pill ml-auto">140</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link d-flex align-items-center" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link B
<span class="badge badge-warning badge-pill ml-auto">300</span>
</a>
</li>
</ul>