我正在尝试使导航栏文本居中,并且尝试了很多事情。以前的答案似乎都没有用。我正在使用Bootstrap中的模板。
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<a class="navbar-brand" href="#"><img id="nav-logo" src="https://site571255.nestifycdn.com/wp-content/uploads/2018/01/PoppysQuesadilla-3.png"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active " href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link " href="#">Features</a>
<a class="nav-item nav-link" href="#">Pricing</a>
<!-- <a class="nav-item nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> -->
</div>
</div>
</nav>
答案 0 :(得分:1)
如果您想将所有内容居中,请遵循以下代码:
<nav class="navbar navbar-expand-sm navbar-light bg-light" data-toggle="affix">
<div class="mx-auto d-sm-flex d-block flex-sm-nowrap">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExample11" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse text-center" id="navbarsExample11">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>