Bootstrap中导航栏和Jumbotron之间的间距问题

6
对于我来说,我无法确定我的导航和jumbotron之间的空白是从哪里来的,我已经尝试了很多变量,但是无法消除它。我在这里创建了一个cssdeckhttp://cssdeck.com/labs/u6ws0ozl ,我的代码如下(省略Bootstrap代码)。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="shift.css" rel="stylesheet">
<link href="http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" />
</head>

<body>
<nav class="navbar navbar-static-top" role="navigation">
  <div class="container-fluid">
    <!-- Collect the nav links, forms, and other content for toggling -->
    <!-- <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> -->
      <ul class="nav nav-pills pull-left">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">About Us</a></li>
      </ul>
      <form class="navbar-form navbar-right navbar-custom pull-right" role="search">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav nav-pills pull-right">
        <li><a href="#">Log In</a></li>
        <li><a href="#">Help</a></li>
      </ul>
    <!-- </div> /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
<div class="jumbotron">
      <div class="container">
        <h1>Find a place to stay.</h1>
        <p>Rent from people in over 34,000 cities and 192 countries.</p>
        <a href="#">Learn More</a>
      </div>
    </div> 
</body>
</html>

CSS(层叠样式表):
@charset "UTF-8";
/* CSS Document */

.navbar {
    background-color: #2c3e50;
}

.nav-pills {
    padding-top: 20px;
    padding-bottom: 20px;
    padding-right: 15px;
    padding-left: 15px;
    /*background-color: #2c3e50;*/
    /*background-color: #2ecc71;*/
}

.nav > li > a:hover,
.nav > li > a:focus {
  text-decoration: none;
  background-color: #2ecc71;
}

.nav-pills > li.active > a,
.nav-pills > li.active > a:hover,
.nav-pills > li.active > a:focus {
  color: #fff;
  background-color: #2ecc71;
}

.navbar-custom {
    padding-top: 20px;
}

.nav a {
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  font-family: 'Shift', sans-serif;
  /*padding: 14px 14px;*/
  text-transform: uppercase;
}

.nav li {
  display: inline;
}

.jumbotron {
  background-image:url('http://goo.gl/04j7Nn');
  height: 500px;
}

.jumbotron .container {
  margin-top: 0px;
  position: relative;
  top:100px;
}

.jumbotron h1 {
  color: #fff;
  font-size: 48px;  
  font-family: 'Shift', sans-serif;
  font-weight: bold;
}

.jumbotron p {
  font-size: 20px;
  color: #fff;
}

.learn-more {
  background-color: #f7f7f7;
}

.learn-more h3 {
  font-family: 'Shift', sans-serif;
  font-size: 18px;
  font-weight: bold;
}

.learn-more a {
  color: #00b0ff;
}

.neighborhood-guides {
    background-color: #efefef;
    border-bottom: 1px solid #dbdbdb;
}

.neighborhood-guides h2 {
    color: #393c3d;
    font-size: 24px;
}

.neighborhood-guides p {
    font-size: 15px;
    margin-bottom: 13px;
}
2个回答

9
从css/bootstrap.css中删除以下内容。
.navbar{
   margin-bottom: 20px;
}

或者您也可以通过在自己的css文件中添加margin:0;来覆盖它:

.navbar {
    background-color: #2c3e50;
    margin:0; /*add this*/
}

Live demo


2
最好在你自己的CSS中覆盖它,而不是像那样编辑库。 - Nick M

0

你需要移除

.jumbotron{

    margin-bottom:20px;
          }

如果你的布局是:
jumbotron
(间隔)
navbar
那么仅仅移除 .navbar 的 margin 是无法达到预期效果的,因为 .jumbotron 有 margin-bottom:20px;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接