简体   繁体   English

带有右对齐项目的引导导航栏

[英]Bootstrap NavBar with right aligned items

I'm trying to align my navbar to the right in bootstrap 4.3.1.我正在尝试在引导程序 4.3.1 中将导航栏与右侧对齐。 I want to have the navbar-brand on the right and navbar-item on the leftBut everything I try does not seem to work.我想在右边有 navbar-brand,在左边有 navbar-item 但是我尝试的一切似乎都不起作用。

this is how it look right now i want to be like this这就是它现在的样子我想变成这样

This is my code:这是我的代码:

 <nav class="navbar navbar-expand-lg navbar-dark"> <div class="container"> <a class="navbar-brand" href="index.php"> <img src="image/logo.svg" width="30" height="30" class="d-inline-block align-top" style="filter: invert(1)" alt=""> my new website </a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbar"> <ul class="navbar-nav mr-auto mt-2 mt-lg-0"> <?php $uri = $_SERVER['REQUEST_URI']; ?> <li class="nav-item <?= $uri == '/test.php'? 'active': ''?>"> <a class="nav-link" href="test.php">test</a> </li> <li class="nav-item <?= $uri == '/test.php'? 'active': ''?>"> <a class="nav-link" href="tset.php">test</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">other</a> <div class="dropdown-menu"> <a class="dropdown-item <?= $uri == '/test.php'? 'active': ''?>" href="test.php">test</a> <div class="dropdown-divider"></div> <a class="dropdown-item <?= $uri == '/test.php'? 'active': ''?>" href="stat.php">test</a> </div> </li> </ul> <ul class="navbar-nav my-2 my-lg-0" style="flex-direction: row;"> <li class="nav-item"> <a class="nav-link" style="padding-right: .5rem;padding-left: .5rem;" href="https://facebook.com" target="_blank"> <img src="images/facebook.svg" width="24" height="24" class="d-inline-block align-top" style="filter: invert(1)" alt=""> </a> </li> <li class="nav-item"> <a class="nav-link" style="padding-right: .5rem;padding-left: .5rem;" href="https://github.com" target="_blank"> <img src="images/github.svg" width="24" height="24" class="d-inline-block align-top" style="filter: invert(1)" alt=""> </a> </li> </ul> </div> </div> </nav>

Try adding d-flex flex-row-reverse to the nav's class.尝试将d-flex flex-row-reverse添加到导航的 class。 After that, you should try to change the order if there is something wrong (I think the images won't be in the right order).之后,如果有问题,您应该尝试更改顺序(我认为图像的顺序不正确)。 Also, I think you should put the .container div to the outside of your nav or even the whole page.另外,我认为您应该将.container div 放在导航甚至整个页面的外部。 Here's the bootstrap 4.4 doc about flex这是关于 flex 的 bootstrap 4.4 文档

Simply add style float:left and float:right for respective elements.只需为各个元素添加样式 float:left 和 float:right 即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM