gpt4 book ai didi

css - 在 Bootstrap 4 (alpha 5) 中将导航栏内容居中

转载 作者:技术小花猫 更新时间:2023-10-29 11:16:55 26 4
gpt4 key购买 nike

我试图在 Bootstrap 4, alpha 5 中将导航栏内容居中。我在谷歌上搜索了一下,我想可能有一些技巧涉及 d-blockmx-自动

但是我无法找到如何将导航链接居中以便它们完全居中,而不仅仅是在它们周围添加一个容器。

我正在玩的示例导航栏代码:。

<nav class="navbar navbar-light bg-faded">
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>

JSFiddle if you like

最佳答案

在 Bootstrap 4 中使 Navbar 元素居中更简单,并且不需要额外的标记。

<nav class="navbar navbar-expand-md navbar-light bg-faded">
<ul class="navbar-nav mx-auto">
<li class="nav-item active text-center">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item text-center">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown text-center">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>

Bootstrap 4 Center Navbar Demo (针对 v4.0.0 更新)

如果您只需要将特定元素居中,例如品牌或链接,see this answer

关于css - 在 Bootstrap 4 (alpha 5) 中将导航栏内容居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40516523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com