使用Bootstrap 5导航栏,如果想让左对齐的项目在右下方溢出,可以通过以下步骤实现:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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="#">项目1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">项目2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">项目3</a>
</li>
</ul>
</div>
</div>
</nav>
float-end
类来实现项目右对齐,并使用overflow-hidden
类来隐藏溢出的项目。例如:.navbar-nav {
float: right;
}
.navbar-nav .nav-item {
float: left;
}
.navbar-nav .nav-item.float-end {
float: right;
}
.overflow-hidden {
overflow: hidden;
}
float-end
类和overflow-hidden
类。例如:<li class="nav-item float-end overflow-hidden">
<a class="nav-link" href="#">项目3</a>
</li>
通过以上步骤,可以实现使用Bootstrap 5导航栏时,让左对齐的项目在右下方溢出的效果。
领取专属 10元无门槛券
手把手带您无忧上云