Bootstrap固定Navbar重叠内容

时间:2015-09-16 20:51:47

标签: html css twitter-bootstrap

我目前正在开发一个用于FCC的Bootstrap项目,到目前为止我还没有遇到任何问题,但是,我遇到的一个小麻烦就是每当我使用导航跳转到链接时吧,它覆盖了显示内容的顶部。我已尝试过这个网站上的用户的其他建议,甚至有点边缘玩,但我还没有想出一个解决方案。

这是我的项目:http://codepen.io/Jelani/full/jbboQE/

    <div class="row">
  <div class="col-md-12">
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class='col-md-12'>
          <div class="navbar-header">
            </button> <a class="navbar-brand" href="#">Jelani Thompson</a>
          </div>
          <!--Try to implement smooth scrolling with nav buttons-->
          <ul class="nav navbar-nav navbar-right">
            <li>
              <a href="#about">About</a>
            </li>
            <li>
              <a href="#portfolio">Portfolio</a>
            </li>
            <li>
              <a href="#contact">Contact</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>
  </div>
</div>

<body>
  <div class="section" id="intro">
  </div>
  <div class="section" id="about">
    <h2 id="about">                     About Me</h2>
    <p>
      "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
      animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
      est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
      voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."</a>
    </p>
  </div>
  <div class="section" id="portfolio">
    <h2 id="portfolio">                     Portfolio</h2>
    <p>
      "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
      sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
      incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea
      voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
    </p>
  </div>

  <div class="section" id="contact">
    <h2 id="contact">                       Contact</h2>
    <p>
      "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human
      happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or
      pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise,
      except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
    </p>
  </div>
</body>

以下是编辑:http://codepen.io/Jelani/pen/jbboQE?editors=110

任何帮助将不胜感激!提前谢谢!

1 个答案:

答案 0 :(得分:2)

您需要考虑导航栏的高度,因为它已修复。最简单的方法是将padding-top等效或大于导航栏的高度添加到<div>类的每个section

演示:http://codepen.io/techsock/pen/PPNPQr?editors=110

CSS:

.section {
  width: 100%;
  height: 100%;
  padding-top:50px;
}