jquery - 导航下方/后方的 Bootstrap 内容

标签 jquery html css twitter-bootstrap twitter-bootstrap-3

为什么相同的代码在 bootstrap 示例中具有很好的上边距,但如果我将其放在 jsfiddle 中,内容就会位于导航下方

http://jsfiddle.net/a60x81gw/

http://getbootstrap.com/examples/starter-template/

我正在使用这些库

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

代码

    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" 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="#">Project name</a>
    </div>
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</div>

<div class="container">

  <div class="starter-template">
    <h1>Bootstrap starter template</h1>
    <p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
  </div>

</div>

最佳答案

该模板在 body 上包含一个 padding,以避免与固定导航栏重叠。

body {
  padding-top: 50px;
}

如文档中所述:

Body padding required The fixed navbar will overlay your other content, unless you add padding to the top of the body. Try out your own values or use our snippet below. Tip: By default, the navbar is 50px high.

http://getbootstrap.com/components/#navbar-fixed-top

关于jquery - 导航下方/后方的 Bootstrap 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26677127/

相关文章:

html - 为 cgi.pm 文件添加 css

javascript - 无法使用 JQuery 设置 Select2 下拉值

javascript - 如何从数组外部删除双引号?

javascript - 使用 ember 的垂直图

jquery - 使用显示后无法隐藏 div :block

php - PHP uniqid 对于 HTML id 属性安全吗?

javascript - AngularJS:请求的资源上不存在 'Access-Control-Allow-Origin' header

javascript - 将链接替换为其他链接中的文本内容 - 抽象代码

javascript - 在深层对象中按名称查找属性

javascript - Angularjs 替换现有的表情符号显示