gpt4 book ai didi

html - bootstrap css 搜索框不适合导航栏

转载 作者:行者123 更新时间:2023-11-28 15:21:19 24 4
gpt4 key购买 nike

在我的 jsp 页面中,我想将 searchbox 放在导航栏元素中。所以我已经完成了下面的代码,单击链接(jsfiddle 代码)。

jsfiddlecode link

但问题是,在移动 View 中,搜索栏不适合导航栏元素。为什么它不适合导航栏??

最佳答案

您可以将按钮和搜索表单放在 navbar-header div 中,这样当点击切换按钮时它不会与移动 navbar 混在一起因为它目前包含在导航链接中。然后你只需要调整切换按钮的位置。

*我还调整了您的 navbar-nav,因为它以特定宽度与搜索按钮重叠。

查看工作示例代码段。

$('#buttonsearch').click(function() {
$('#formsearch').slideToggle("fast", function() {
$('#content').toggleClass("moremargin");
});
$('#searchbox').focus()
$('.openclosesearch').toggle();
});
body {
padding-top: 70px;
}
.searchbardiv {
display: block;
position: fixed;
background: #7D1935;
top: 50px;
right: 0px;
width: 100%;
max-width: 100%;
padding: 10px;
margin: 0px;
}
#formsearch {
display: none;
}
.buttonsearch {
position: fixed;
color: white;
top: 15px;
right: 10px;
background-color: transparent;
border: 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.buttonsearch:hover {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: 0px;
}
.buttonsearch:focus {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
outline: none;
border: 0px;
}
.glyphicon.glyphicon-search {
font-size: 18px;
}
#searchbox {
box-shadow: none;
padding: 8px 14px;
}
#searchbox:hover {
box-shadow: none;
}
.form-control:focus {
border-color: #ccc;
}
@media (min-width: 768px) {
.navbar .navbar-nav {
margin-right: 10px;
}
}
@media (max-width: 767px) {
.navbar .navbar-toggle {
margin-right: 50px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
<a class="navbar-brand" href="#">MyCompany</a>
<button type="button" class="buttonsearch" id="buttonsearch">
<i class="glyphicon glyphicon-search openclosesearch"></i>
<i class="glyphicon glyphicon-remove openclosesearch" style="display:none"></i>
</button>
<form role="search" method="get" class="searchbardiv" id="formsearch">
<div class="input-group">
<input type="text" id="searchbox" class="form-control" name="s" id="s">
<div class="input-group-btn">
<button class="btn btn-default" id="searchsubmit" type="submit">
<strong>Search</strong>
</button>
</div>
</div>
</form>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="home.html"> Home</a>
</li>
<li>
<a href="home.html"> link1</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="well">
Content
</div>
</div>

关于html - bootstrap css 搜索框不适合导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34462180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com