要使Bootstrap导航栏居中并具有特定的宽度,可以通过以下步骤实现:
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
<div class="container text-center">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<!-- 导航栏内容 -->
</nav>
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light" style="width: 800px;">
<!-- 导航栏内容 -->
</nav>
或者
<style>
.custom-navbar {
width: 800px;
}
</style>
<nav class="navbar navbar-expand-lg navbar-light bg-light custom-navbar">
<!-- 导航栏内容 -->
</nav>
<nav class="navbar navbar-expand-lg navbar-light bg-light custom-navbar">
<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 ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
总结:通过添加容器的CSS类名、设置导航栏的特定宽度,并根据需要调整内部元素的排列方式和样式,可以使Bootstrap导航栏居中并具有特定的宽度。
领取专属 10元无门槛券
手把手带您无忧上云