twitter-bootstrap 引导程序中导航和超大屏幕之间的差距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24337758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:59:35  来源:igfitidea点击:

Gap between nav and jumbotron in bootstrap

htmlcsstwitter-bootstrapweb

提问by SuperAdmin

For the life of me I can't determine where the white space between my nav and jumbotron is coming from, I have played with so many variables, but cant get it to go away. I made a cssdeck here http://cssdeck.com/labs/u6ws0ozland my code is below (Bootstrap code omitted).

对于我的一生,我无法确定导航和超大屏幕之间的空白来自哪里,我玩过这么多变量,但无法让它消失。我在这里做了一个 cssdeck http://cssdeck.com/labs/u6ws0ozl,我的代码在下面(省略了引导代码)。

HTML:

HTML:

<!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:

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;
}

回答by CMPS

Remove the following from css/bootstrap.css

从 css/ bootstrap.css 中删除以下内容

.navbar{
   margin-bottom: 20px;
}

Or you can also override it by adding margin:0;to your own css file:

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

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

Live demo

现场演示

回答by Syed Ali

You have to remove

你必须删除

.jumbotron{

    margin-bottom:20px;
          }

if your layout is:
jumbotron
(Gap)
navbar
Then removing .navbar margin alone will not achieve desired effect as.jumbotron has margin-bottom:20px;

如果您的布局是:
jumbotron
(Gap)
navbar
那么单独删除 .navbar margin 不会达到预期的效果,因为 .jumbotron 有 margin-bottom:20px;