我试图找到问题,但对我没什么用。
如果我正在调整浏览器的大小,那么汉堡包菜单会弹出并正常工作,但是当我在手机上查看它时,它无法正常工作。 我真的做错了吗?
我正在使用的代码:
HTML:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Roy van Eerden</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#about">Home</a></li>
<li><a href="#skills">Portfolio</a></li>
<li><a href="#experience">Over</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</nav>
看到它
手机示例的屏幕截图:
答案 0 :(得分:3)
只需在头部添加此元标记
即可<meta name="viewport" content="width=device-width, initial-scale=1.0">
答案 1 :(得分:2)
将jquery.js放在bootstrap.min.js
之上另外,添加meta in head
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
点击这里
答案 2 :(得分:0)
您缺少整个html部分,请从此处替换您的导航内容(w3school文档)。
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>