问题描述
导航栏显示我的品牌,但不显示菜单项. Bootstrap 4依存关系的顺序正确(Bootstrap 4 CSS-> Jquery-> Popper-> Bootstrap JS).<head>
中引用的元视点.
Navbar is showing my branding, but not showing menu items. Bootstrap 4 dependencies are in right order (Bootstrap 4 CSS -> Jquery -> Popper -> Bootstrap JS).Meta viewpoint referenced in <head>
.
HTML:
<nav class="navbar navbar-light bg-faded">
<a class="navbar-brand" onclick="goBack()">
<img src="icon.jpg" width="30" height="30" class="d-inline-block align-top" alt="">
Back to Course
</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
CSS:
@font-face {
font-family: Helvetica;
src: url(HelveticaNeue BlackCond.ttf);
}
@media (min-width: 992px) {
.navbar-nav li a { line-height: 80px; }
}
@media (max-width: 991px) {
.navbar-brand { float: none; }
}
.navbar-brand {
font-family: 'Helvetica';
font-weight: 500;
}
.container {
padding-top: 2em;
}
推荐答案
这是因为代码中缺少navbar-expand-*
类.
That's because the navbar-expand-*
class is missing in your code.
我在下面的代码片段中添加了navbar-expand-md
.此类在中等(md
)或更大的屏幕上展开导航栏(从默认的折叠状态开始).
I've added navbar-expand-md
in the code snippet below. This class expands the navbar (from the default collapsed state) on screens that are medium (md
) or larger.
如果将其更改为navbar-expand-lg
,则会从大屏幕(lg
)等开始进行扩展.
If you change that to navbar-expand-lg
, the expansion will happen form large (lg
) screens onwards etc.
如果您想永久地扩展导航栏项,即在所有屏幕尺寸上永久扩展,请使用navbar-expand
类.
And if you want your navbar items to be expanded permanently i.e. on all screen sizes, use the navbar-expand
class.
您还需要 toggler ,以便在折叠导航栏时打开和关闭导航栏项目.您的代码中目前也缺少该切换器.
You also need a toggler in order to open and close the navbar items when the navbar is collapsed. That toggler is currently missing in your code as well.
点击下面的运行代码段",然后展开到整页进行测试:
Click "run code snippet" below and expand to full page for testing:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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>
<nav class="navbar navbar-expand-md navbar-light bg-faded">
<a class="navbar-brand" onclick="goBack()">
<img src="https://placehold.it/30" width="30" height="30" class="d-inline-block align-top" alt="">
Back to Course
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<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="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
这篇关于Bootstrap 4导航栏不显示导航栏项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!