在Bootstrap 4导航栏导航项目中创建居中和下方的小文本对齐图标,可以通过以下步骤实现:
<span>
标签来包裹图标和文本。nav-item-icon
的类。nav-item-icon
类的样式。可以使用Flexbox布局来实现居中和下方对齐的效果。.nav-item-icon {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.nav-item-icon span {
margin-top: 5px; /* 调整文本与图标的间距 */
}
nav-item-icon
类。<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">
<span class="nav-item-icon">
<i class="fa fa-home"></i>
<span>首页</span>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span class="nav-item-icon">
<i class="fa fa-user"></i>
<span>个人中心</span>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span class="nav-item-icon">
<i class="fa fa-envelope"></i>
<span>消息</span>
</span>
</a>
</li>
</ul>
</div>
</nav>
这样,每个导航项目的图标和文本就会居中且下方对齐,而不会影响导航栏的高度。你可以根据需要自定义图标和文本的样式,并根据实际情况选择合适的图标库。
领取专属 10元无门槛券
手把手带您无忧上云