使用新的Bootstrap 4 v4.0.0-beta.2,我无法找到一种方法来将内容集中在我的导航栏中。我已经尝试了一切!有任何想法吗?代码如下。
早期的答案是关于ALPHA发布的bootstrap 4,我已经尝试过了!他们的解决方案不起作用。
<nav class="navbar navbar-expand-md navbar-light fixed-top">
<a class="navbar-brand" href="/">
<img src="/img/frontpage/logotest.png">logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
</ul>
</div>
</nav>
答案 0 :(得分:6)
试试这段代码。它适用于bootstrap 4.我刚刚将d-flex justify-content-center
添加到navbar-collapse。
<nav class="navbar navbar-expand-md navbar-light fixed-top">
<a class="navbar-brand" href="/">
<img src="/img/frontpage/logotest.png">logo
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex justify-content-center" id="navbarsExampleDefault">
<ul class="navbar-nav ">
<li class="nav-item "><a class="nav-link" href="/">Home</a></li>
</ul>
</div>
</nav>
答案 1 :(得分:0)
您只需要添加.justify-content-center类
min(id)