我有一个带有navbar toggler for mobile的网站导航栏,我试图获得两个导航项(用于登录/注册等)以对齐导航栏的右侧,但无论出于何种原因,建议的方法使用navbar-right
类将无效。
以下是代码:
<!-- Navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="/index.php"><img src="/assets/img/logo_white.png" style="height: 35px;"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="nav navbar-nav">
<li class="nav-item <?php if ($sect == 'home') { echo 'active';} ?>">
<a class="nav-link" href="/index.php">Home</a>
</li>
<li class="nav-item dropdown <?php if ($sect == 'about') { echo 'active';} ?>">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item <?php if ($page == 'about-us') { echo 'active';} ?>" href="/about/about-us.php">About Us</a>
<a class="dropdown-item <?php if ($page == 'staff') { echo 'active';} ?>" href="/about/staff.php">Staff Team</a>
<a class="dropdown-item <?php if ($page == 'partners') { echo 'active';} ?>" href="/about/partners.php">Partners</a>
</div>
</li>
<li class="nav-item dropdown <?php if ($sect == 'resources') { echo 'active';} ?>">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item <?php if ($page == 'downloads') { echo 'active';} ?>" href="/resources/downloads.php">Downloads</a>
<a class="dropdown-item <?php if ($page == 'charts') { echo 'active';} ?>" href="/resources/charts.php">Charts</a>
<a class="dropdown-item <?php if ($page == 'metar') { echo 'active';} ?>" href="/resources/metar.php">METAR Decoder</a>
</div>
</li>
<li class="nav-item <?php if ($sect == 'academy') { echo 'active';} ?>">
<a class="nav-link" href="/academy/index.php">Academy</a>
</li>
<li class="nav-item <?php if ($sect == 'fly') { echo 'active';} ?>">
<a class="nav-link disabled" href="#">Fly</a>
</li>
<li class="nav-item <?php if ($sect == 'forums') { echo 'active';} ?>">
<a class="nav-link" href="https://forums.multicrew.co.uk/">Forums</a>
</li>
<li class="nav-item <?php if ($sect == 'book') { echo 'active';} ?>">
<a class="nav-link" href="https://multicrew.setmore.com/">Book</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="nav-item">
<a class="nav-link" href="https://portal.multicrew.co.uk/"><i class="fa fa-sign-in"></i> Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://portal.multicrew.co.uk/register"><i class="fa fa-user"></i> Register</a>
</li>
</ul>
</div>
</nav>
<!--/END Navbar-->
看到输出
答案 0 :(得分:0)
查看您使用bootstrap 4的站点链接,它不使用类似“navbar-right”的类,如bootstrap 3
我找到了一些bootstrap 4导航示例,可以帮助您进行菜单布局, https://www.codeply.com/go/qhaBrcWp3v 希望它有所帮助
答案 1 :(得分:0)
我将代码中的navbar-right
类替换为 Bootstrap 4类 ml-auto
(margin-left:auto),现在它已根据需要运行。
以下是工作代码段(单击&#34;运行代码段&#34;按钮如下):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-md navbar-dark navbar-static-top bg-dark">
<a class="navbar-brand" href="/index.php"><img src="https://picsum.photos/55" style="height: 35px;"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="nav navbar-nav">
<li class="nav-item ">
<a class="nav-link" href="/index.php">Home</a>
</li>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
About
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item active" href="/about/about-us.php">About Us</a>
<a class="dropdown-item " href="/about/staff.php">Staff Team</a>
<a class="dropdown-item " href="/about/partners.php">Partners</a>
</div>
</li>
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Resources
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item " href="/resources/downloads.php">Downloads</a>
<a class="dropdown-item " href="/resources/charts.php">Charts</a>
<a class="dropdown-item " href="/resources/metar.php">METAR Decoder</a>
</div>
</li>
<li class="nav-item ">
<a class="nav-link disabled" href="/academy/index.html">Academy</a>
</li>
<li class="nav-item ">
<a class="nav-link disabled" href="#">Fly</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="https://forums.multicrew.co.uk/">Forums</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="https://multicrew.setmore.com/">Book</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="https://portal.multicrew.co.uk/"><i class="fa fa-sign-in"></i> Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://portal.multicrew.co.uk/register"><i class="fa fa-user"></i> Register</a>
</li>
</ul>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
&#13;