我想在导航栏崩溃时显示我的搜索栏。
我的代码:http://jsfiddle.net/edalzell/a3yng825/1/在折叠时有效,但在展开时显示两个搜索栏。
HTML:
<header class= "blog-masthead">
<nav class="navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed pull-left" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<form class="navbar-form collapsed navbar-right" role="search" action="/search" method="get">
<div class="form-group input-group">
<input type="text" class="form-control input-sm" placeholder="Search" id="sitesearch" name="query">
<span class="input-group-addon"><button type="submit" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></button></span>
</div>
</form>
</div> <!-- navbar-header -->
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<li><a href="/blog">Blog</a></li>
<li><a href="/about">About</a></li>
</ul>
<form class="navbar-form navbar-right" role="search" action="/search" method="get">
<div class="form-group input-group">
<input type="text" class="form-control input-sm" placeholder="Search" id="sitesearch" name="query">
<span class="input-group-addon"><button type="submit" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></button></span>
</div>
</form>
</div> <!-- navbar-collapse -->
</div>
</nav>
</header>
答案 0 :(得分:5)
那是因为您声明了两个搜索栏,您有几个选项可以获得所需的结果
删除您在折叠中声明的额外搜索栏 部分
隐藏/显示所需分辨率的特定项目,您可以查看 this SO thread
我使用了第一种方法,你可以找到jsfiddle here
完整代码:
<header class= "blog-masthead">
<nav class="navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed pull-left" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<form class="navbar-form collapsed navbar-right" role="search" action="/search" method="get">
<div class="form-group input-group">
<input type="text" class="form-control input-sm" placeholder="Search" id="sitesearch" name="query">
<span class="input-group-addon"><button type="submit" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-search"></span></button></span>
</div>
</form>
</div> <!-- navbar-header -->
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-left">
<li><a href="/blog">Blog</a></li>
<li><a href="/about">About</a></li>
</ul>
</div> <!-- navbar-collapse -->
</div>
</nav>
</header>