我使用bootstrap为我的“home.html”使用下面给出的代码。 但是,通过移动设备浏览网站时,搜索栏及其中的所有内容都无法显示。 请帮帮忙!谢谢!
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar">
<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="/">Get Started</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<form class="navbar-form navbar-left" role="search" action="/search/" method="GET" id="search" autocomplete="off">
<div class="form-group">
<input type="text" class="form-control" placeholder="Select what to search for" name="query" width="100px">
<select name="drop" class="form-control" width="20">
<option value="1"> Assigns</option>
<option value="2"> Subjects(Tutorials)</option>
<option value="3"> Subjects(Papers)</option>
</select>
</div>
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
</form>
</li>
<li>
<a href="#home">Home</a>
</li>
<li>
<a href="#about">About</a>
</li>
<li>
<a href="#contact">Contact us</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
答案 0 :(得分:2)
折叠导航栏时显示的按钮的data-target
指向不存在的元素ID(#navigationbar)。将它指向折叠元素(#bs-example-navbar-collapse-1)。
...
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
...
答案 1 :(得分:1)
您的切换目标与您的折叠ID不匹配:
<button type="button"... data-target="#navigationbar">
<div class="collapse navbar-collapse" id="navigationbar">
答案 2 :(得分:0)
检查页面上的所有库是nav-collapse所需的基本库是bootstrap和jquery,您可以将下一个脚本添加到头代码中
http://getbootstrap.com/getting-started/
https://cdnjs.com/libraries/jquery/
对于另一个验证,数据切换具有与导航栏相关的正确ID