我的网络应用程序中有两个 navbars
。但是,这两个 navbars
之间有一个空格,如下图所示。
我试过 .navbar {margin-bottom:0px}
但没有运气。
这是我的HTML



< link rel =“stylesheet”href =“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”>
< ;风格>&#的xD;
 .navbar {margin-bottom:0px}
< / style>
<! - jQuery库 - >
< ; script src =“https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js”>< / script>

 
<! - 最新编译的JavaScript - >
< script src =“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap。 min.js“>< / script>
< nav class =”navbar navbar-default“id =”navbar-no-margin“>
 < div class =“container”>
 < div class =“navbar-header”>
 < a class =“navbar-brand”href =“#”>品牌< / a>
 < / DIV>&#的xD;
&#的xD;
 < div class =“collapse navbar-collapse”>
 < ul class =“nav navbar-nav navbar-right”>
 < li>< a href =“#”data-toggle =“modal”data-target =“#signinmodal”>登录< / a>< / li>
 < li>< a href =“#”data-toggle =“modal”data-target =“#signupmodal”>注册< / a>< / li>
 < / UL>&#的xD;
 < / div><! - /.navbar-collapse - >
 < / div><! - /.container-->
< / NAV>&#的xD;
&#的xD;
 < nav class =“navbar navbar-default”id =“navbar-no-margin”>
 < div class =“container”>
 < div class =“navbar-header”>
 < a class =“navbar-brand”href =“#”>品牌< / a>
 < / DIV>&#的xD;
&#的xD;
 < div class =“collapse navbar-collapse”>
 < ul class =“nav navbar-nav navbar-right”>
 < li>< a href =“#”data-toggle =“modal”data-target =“#signinmodal”>登录< / a>< / li>
 < li>< a href =“#”data-toggle =“modal”data-target =“#signupmodal”>注册< / a>< / li>
 < / UL>&#的xD;
 < / div><! - /.navbar-collapse - >
 < / div><! - /.container-->
< / NAV> 代码>
&#的xD;
 答案 0 :(得分:0)
将body
' s padding-top
设为50px
。
body {
padding-top: 50px;
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default navbar-fixed-top" id="navbar-no-margin">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" data-toggle="modal" data-target="#signinmodal">Sign in</a></li>
<li><a href="#" data-toggle="modal" data-target="#signupmodal">Sign up</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-->
</nav>
<nav class="navbar navbar-default" id="navbar-no-margin">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" data-toggle="modal" data-target="#signinmodal">Sign in</a></li>
<li><a href="#" data-toggle="modal" data-target="#signupmodal">Sign up</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-->
</nav>
&#13;
答案 1 :(得分:0)
您需要将position属性设置为relative而不是fixed,并将margin bottom设置为0。
.navbar-default {
position: relative;
margin-bottom: 0;
}
下面是一个显示输出的Jsfiddle。 https://jsfiddle.net/niteshp27/vkntcdbf/
答案 2 :(得分:0)
important
将margin-bottom
添加到规则末尾会覆盖bootstrap
中if
的默认样式。