搜索框在调整大小时将导航栏的高度加倍

时间:2018-09-24 06:31:40

标签: html css twitter-bootstrap-3 mezzanine

我有一个Bootstrap 3响应式导航栏,左侧带有菜单项,右侧是一个搜索框,其宽度大于990px​​且宽度小于765px时看起来很好(高度50px)(菜单缩小为一个图标),但在这些宽度之间,搜索框会上升到菜单上方,并使导航栏的高度加倍,从而开始覆盖我的内容:

好:

enter image description here

坏:

enter image description here

阻止这种行为的最佳方法是什么? (我不想让导航栏更高。)这是我的当前代码:

<!doctype html>
<html lang="en">

<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body id="body" style="padding-top: 50px;">

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container nav-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>
</div>
<div class="navbar-collapse collapse">

<form action="/search/" class="navbar-form navbar-right" role="search">
<div class="form-group">
    <input class="form-control" placeholder="Search" type="text" name="q" value="">
</div>

    <div class="form-group">
    <select class="form-control" name="type">
        <option value="">Everything</option>
        <option value="blog.BlogPost" >Blog posts</option>
    </select>
    </div>
<input type="submit" class="btn btn-default" value="Go">
</form>

<ul class="nav navbar-nav">
<li class="active"><a href='#'>Home</a></li>
<li><a href='#'>Item One</a></li>
<li><a href='#'>Item Two</a></li>
<li><a href='#'>Another Item</a></li>
<li><a href='#'>About</a></li>
</ul>

</div>
</div>
</div>


<div class="front-page-container">
<h1>MAIN HEADING</h1>
<h2>Sub-heading</h2>

</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要为其屏幕991px到767px添加自定义css

@media (max-width: 991px) and (min-width: 767px){
.navbar .container {
    width: 100%!important;
}
.navbar-form .form-group {
    width: 120px;
}
.nav>li>a {
    padding: 10px 10px;
}
.navbar-form .form-control{
width:100%!important;}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body id="body" style="padding-top: 50px;">

<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container nav-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>
</div>
<div class="navbar-collapse collapse">

<form action="/search/" class="navbar-form navbar-right" role="search">
<div class="form-group">
    <input class="form-control" placeholder="Search" type="text" name="q" value="">
</div>

    <div class="form-group">
    <select class="form-control" name="type">
        <option value="">Everything</option>
        <option value="blog.BlogPost" >Blog posts</option>
    </select>
    </div>
<input type="submit" class="btn btn-default" value="Go">
</form>

<ul class="nav navbar-nav">
<li class="active"><a href='#'>Home</a></li>
<li><a href='#'>Item One</a></li>
<li><a href='#'>Item Two</a></li>
<li><a href='#'>Another Item</a></li>
<li><a href='#'>About</a></li>
</ul>

</div>
</div>
</div>


<div class="front-page-container">
<h1>MAIN HEADING</h1>
<h2>Sub-heading</h2>

</div>
</body>