我目前正在使用Bootstrap创建一个网站,问题是在响应式小显示菜单上我希望将搜索输入显示在其他内容上,但我没有这样做。我正在使用jQuery。
预期的用途是,当按下搜索图标按钮时,它会显示隐藏的输入,而不是其他元素的全尺寸可用,再次单击按钮并使其消失,但如果不给予我,我无法想办法表单的宽度为100%,但它会使布局崩溃。我正在连接一个jsfiddle以启发它。此按钮和表单仅在小分辨率下可见。
HTML
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">TEST SITE</a>
<form id="form-search" class="navbar-form navbar-collapse visible-xs pull-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Buscar">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"</span></button>
</span>
</div>
</form>
<button id="colapsador" type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<button id="navi-btn" type="button" class="visible-xs btn btn-default pull-right">
<span class="glyphicon glyphicon-map-marker"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Some site</h1>
<p>Some text</p>
</div>
</div>
</div>
的Javascript
$('#form-search button').click(function(){
$(this).css({
'border-top-left-radius':'0',
'border-bottom-left-radius':'0'
}).addClass('active');
$('#form-search').css('width','100%');
$('#form-search .form-control').css({
'display':'inherit',
'width':'100%',
});
});
CSS
#form-search{
border: none;
margin-top: -2px;
margin-right: -0.5em;
width:4.8em;
z-index: 6;
}
#form-search .form-control{
display:none;
z-index: 100;
}
#form-search .input-group-btn button{
border-top-left-radius:4px;
border-bottom-left-radius: 4px;
}
#navi-btn{
margin-top: 8px;
margin-right: 0.5em;
z-index: 1;
}
#colapsador{
margin-right: 0.5em;
z-index: 1;
}
z-index属性似乎不起作用,如果有人可以启发我如何恢复原始css属性再次单击按钮会很好,但这不是我主要关注的问题,我可以搜索它。 / p>
答案 0 :(得分:0)
<强> Updated fiddle 强>
我不确定但是尝试将width
从100%更改为50%:
$('#form-search').css('width','50%');
我认为解决问题,希望这有帮助。
答案 1 :(得分:0)
z-index属性似乎无法正常工作
对于z-index,您需要在要在其上设置z-index的每个元素上使用position:absolute
答案 2 :(得分:0)
我终于做到了,只是细微的细节,动画仍然缺失,但这完美无缺:)
检查更新的小提琴
http://jsfiddle.net/8vv0dgLc/2/
HTML代码:
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">TEST SITE</a>
<form id="form-search" class="navbar-form navbar-collapse visible-xs pull-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Buscar">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search"</span></button>
</span>
</div>
</form>
<button id="colapsador" type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<button id="navi-btn" type="button" class="visible-xs btn btn-default pull-right">
<span class="glyphicon glyphicon-map-marker"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
<div>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Some site</h1>
<p>Some text</p>
</div>
</div>
</div>
的Javascript
$('#form-search button').click(function(){
$('#form-search .form-control').toggle();
});
CSS
#form-search{
border: none;
margin-top: -2px;
margin-right: -0.5em;
width:4.8em;
z-index: 6;
}
#form-search .form-control{
position:absolute;
display:none;
z-index: 100;
right:3em;
width:15em;
}
#form-search .input-group-btn button{
border-top-left-radius:4px;
border-bottom-left-radius: 4px;
}
#navi-btn{
margin-top: 8px;
margin-right: 0.5em;
z-index: 1;
}
#colapsador{
margin-right: 0.5em;
z-index: 1;
}