本文介绍了Bootstrap 4 - 右对齐导航栏项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让所有东西都一致,除了品牌/ title。
这就是我的代码的样子:
< nav class =navbar navbar -tableable-md navbar-inverse bg-inverse>
< button class =navbar-toggler navbar-toggler-righttype =buttondata-toggle =collapsedata-target =#navbarNavAltMarkuparia-controls =navbarNavAltMarkuparia-expanded = falsearia-label =切换导航>
< span class =navbar-toggler-icon>< / span>
< / button>
< a class =navbar-brandhref =#> Oliver< / a>
< div class =collapse navbar-collapseid =navbarNavAltMarkup>
< div class =navbar-nav>
< a class =nav-item nav-link activehref =#>关于< span class =sr-only>(current)< / span>< / a> ;
< a class =nav-item nav-linkhref =#projects>项目< / a>
< a class =nav-item nav-linkhref =#contact>联系人< / a>
< / div>
< / div>
< / nav>
解决方案
您可以添加 .justify -content-end
添加到 .navbar-collapse
元素中。我假设你也想将移动切换菜单项移动到右侧。为此,请将 .align-items-end
添加到 .navbar-nav
< script src =https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1 .1 / jquery.min.js>< / script>< script src =https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/ bootstrap.min.js>< / script>< link href =https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min .cssrel =stylesheet/>< nav class =navbar navbar-toggleable-md navbar-inverse bg-inverse> < button class =navbar-toggler navbar-toggler-righttype =buttondata-toggle =collapsedata-target =#navbarNavAltMarkuparia-controls =navbarNavAltMarkuparia-expanded =falsearia -label =切换导航> < span class =navbar-toggler-icon>< / span> < /按钮> < a class =navbar-brandhref =#> Oliver< / a> < div class =collapse navbar-collapse justify-content-endid =navbarNavAltMarkup> < div class =navbar-nav align-items-end> < a class =nav-item nav-link activehref =#>关于< span class =sr-only>(current)< / span>< / a> < a class =nav-item nav-linkhref =#projects>项目< / a> < a class =nav-item nav-linkhref =#contact>联络人< / a> < / DIV> < / nav>
I'm trying to align my navbar items to the right in bootstrap 4 alpha 6.
I'd like to have everything aligned right, except for the brand/title.
This is what my code looks like:
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Oliver</a>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link active" href="#">About <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#projects">Projects</a>
<a class="nav-item nav-link" href="#contact">Contact</a>
</div>
</div>
</nav>
解决方案
You can add .justify-content-end
to the .navbar-collapse
element. And I'm assuming you also want to move the mobile toggle menu items to the right. To do that, add .align-items-end
to .navbar-nav
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Oliver</a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNavAltMarkup">
<div class="navbar-nav align-items-end">
<a class="nav-item nav-link active" href="#">About <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#projects">Projects</a>
<a class="nav-item nav-link" href="#contact">Contact</a>
</div>
</div>
</nav>
这篇关于Bootstrap 4 - 右对齐导航栏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!