gpt4 book ai didi

javascript - 如何在 Bootstrap 4 中 Justify-End 仅选择导航项?

转载 作者:行者123 更新时间:2023-11-28 04:26:05 25 4
gpt4 key购买 nike

我尝试使用 .justify-content-end 仅将选定的导航项 float 到右侧

如果我将其添加到顶级 div 类,则效果很好,但如果我创建一个特殊的 div 来隔离一个导航项并使用该类,则它不起作用:

<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Bewander</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Create", "Reviews")'>Write a Review </a>
</li>
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Index", "Reviews")'>Search the World</a>
</li>
<div class="justify-content-end">
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Login", "Account")'>Login</a>
</li>
</div>
</ul>
</div>

</nav>

虽然 .justify-content-end 以这种方式工作,但它会移动我不想要的所有元素,因此我尝试隔离特定的导航元素:

<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Bewander</a>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Create", "Reviews")'>Write a Review </a>
</li>
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Index", "Reviews")'>Search the World</a>
</li>
<li class="nav-item">
<a class="nav-link" href='@Url.Action("Login", "Account")'>Login</a>
</li>
</ul>
</div>
</nav>

Here is a codepen to test on

最佳答案

.justify-content-end.navbar-nav 推到末尾,因为它是唯一的子项。

相反,您可以尝试通过应用 flex-grow: 1 来强制 .navbar-nav 增长到全宽。然后,将 margin-left: auto; 应用于要推到右侧的元素。幸运的是,bootstrap 有一个针对后者的实用程序类 - .ml-auto

Updated Codepen

关于javascript - 如何在 Bootstrap 4 中 Justify-End 仅选择导航项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45046174/

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