2015-09-21 3 views
1

Я работаю на мой первый сайт для изучения целей и запустить в эту проблему:Bootstrap Navbar охватывает верхнюю часть секции при связывании

Всякий раз, когда я ссылку на конкретное место на той же странице, она открывает, как предполагалось, но верхняя часть покрыта навигационной панелью.

<body data-spy="scroll" data-target="#myNavbar" data-offset="50"> 
    <nav id="myNavbar" role="navigation" class="container-fluid navbar navbar-default navbar-fixed-top"> 
     <div class="container"> 
     <div class="navbar-header"> 
      <button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle"> 
       <span class="sr-only"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
      </button> 
      <a href="#" class="navbar-brand"></a> 
     </div> 
     <div id="navbarCollapse" class="collapse navbar-collapse"> 

      <ul class="nav navbar-nav navbar-right"> 
       <li><a href="#section1">Home</a></li> 
       <li><a href="#section2">About</a></li> 
       <li><a href="#section3">Portfolio</a></li> 
       <li><a href="#section4">Contact</a></li> 
      </ul> 
     </div> 
     </div> 
    </nav> 

    <div class="jumbotron" id="section1"> 
     <h1 class="header"></h1> 
     <hr class="style" /> 
     <un class="list-inline"> 
     <li> 
      <a href="#"> 
       <span class="glyphicon glyphicon-chevron-left"></span> Facebook 
       <span class="glyphicon glyphicon-chevron-right"></span> 
      </a> 
     </li> 
     <li> 
      <a href="#"> 
       <span class="glyphicon glyphicon-chevron-left"></span> GitHub 
       <span class="glyphicon glyphicon-chevron-right"></span> 
      </a> 
     </li> 
     <li> 
      <a href="#"> 
       <span class="glyphicon glyphicon-chevron-left"></span> LinkedIn 
       <span class="glyphicon glyphicon-chevron-right"></span> 
      </a> 
     </li> 
     </un> 
    </div> 
</body> 

Есть ли способ сделать это ссылкой ниже навигационной панели, чтобы она не покрывала верхнюю часть раздела?

Попробовали играть с обивкой кузова, но не использовать.

(я был в состоянии решить эту проблему путем ссылки на отдельные дивы и регулировать их соперничают CSS, но после выполнения начальной загрузки scrollspy дивы, которые охватывают целый раздел был о быть адресным, таким образом, проблема возвращается.)

PS : не используется JS/Query.

+0

Доля код таким образом, что мы можем помочь вам. –

ответ

0

Это может помочь или дать вам некоторые идеи; вы, по сути, просто используете два навигатора вместе под классом navbar-fixed-top, чтобы потом они были вместе на свитке.

body { 
 
    margin-top: 100px; 
 
    position: relative; 
 
} 
 
.navbar.nav-lower { 
 
    height: 20px; 
 
    background: #f5f5f5; 
 
    border-radius: 0; 
 
    border: none; 
 
    margin-bottom: 0; 
 
} 
 
.nav-lower .navbar-toggle, 
 
.nav-lower .navbar-toggle:focus, 
 
.nav-lower .navbar-toggle:hover { 
 
    border: none; 
 
    background: none; 
 
} 
 
.navbar.nav-lower > li { 
 
    display: inline-block; 
 
    width: 33%; 
 
    text-align: center; 
 
} 
 
#section1 { 
 
    padding-top: 100px; 
 
    height: 500px; 
 
    color: #fff; 
 
    background-color: #1E88E5; 
 
} 
 
#section2 { 
 
    padding-top: 100px; 
 
    height: 500px; 
 
    color: #fff; 
 
    background-color: #673ab7; 
 
} 
 
#section3 { 
 
    padding-top: 100px; 
 
    height: 500px; 
 
    color: #fff; 
 
    background-color: #ff9800; 
 
} 
 
#section4 { 
 
    padding-top: 100px; 
 
    height: 500px; 
 
    color: #fff; 
 
    background-color: #00bcd4; 
 
} 
 
@media (max-width: 767px) { 
 
    .nav-lower .navbar-collapse { 
 
    text-align: left; 
 
    background: #f5f5f5; 
 
    } 
 
} 
 
@media (min-width: 767px) { 
 
    .navbar.navbar-default.nav-lower .navbar-inner { 
 
    padding: 0; 
 
    } 
 
    .navbar.navbar-default.nav-lower .nav { 
 
    margin: 0; 
 
    display: table; 
 
    width: 100%; 
 
    } 
 
    .navbar.navbar-default.nav-lower .nav > li { 
 
    display: table-cell; 
 
    float: none; 
 
    } 
 
    .navbar.navbar-default.nav-lower .nav > li > a { 
 
    text-align: center; 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> 
 

 
<body data-spy="scroll" data-target="#myNavbar" data-offset="100"> 
 
    <nav class="navbar navbar-default navbar-custom navbar-fixed-top" id="myNavbar"> 
 
    <div class="container"> 
 
     <!-- Brand and toggle get grouped for better mobile display --> 
 
     <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <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="#">Brand</a> 
 

 
     </div> 
 
     <!-- Collect the nav links, forms, and other content for toggling --> 
 
     <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
      <li class="active"><a href="#section1">Home</a> 
 

 
      </li> 
 
      <li><a href="#section2">About</a> 
 

 
      </li> 
 
      <li><a href="#section3">Portfolio</a> 
 

 
      </li> 
 
      <li><a href="#section4">Contact</a> 
 

 
      </li> 
 
     </ul> 
 
     </div> 
 
     <!-- /.navbar-collapse --> 
 
    </div> 
 
    <!-- /.container-fluid --> 
 
    <nav class="navbar navbar-default nav-lower"> 
 
     <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-lower-nav" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> 
 
      <span class="glyphicon glyphicon-chevron-down"></span> 
 

 
     </button> 
 
     </div> 
 
     <div class="collapse navbar-collapse" id="bs-lower-nav"> 
 
     <ul class="nav navbar-nav"> 
 
      <li> 
 
      <a href="#"> <span class="glyphicon glyphicon-chevron-left"></span> Facebook 
 
       <span class="glyphicon glyphicon-chevron-right"></span> 
 
      </a> 
 

 
      </li> 
 
      <li> 
 
      <a href="#"> <span class="glyphicon glyphicon-chevron-left"></span> GitHub 
 
       <span class="glyphicon glyphicon-chevron-right"></span> 
 
      </a> 
 

 
      </li> 
 
      <li><a href="#"><span class="glyphicon glyphicon-chevron-left"></span> LinkedIn 
 
       <span class="glyphicon glyphicon-chevron-right"></span></a> 
 

 
      </li> 
 
     </ul> 
 
     </div> 
 
    </nav> 
 
    </nav> 
 
    <div id="section1" class="container-fluid"> 
 
    <h1>Section 1</h1> 
 

 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    </div> 
 
    <div id="section2" class="container-fluid"> 
 
    <h1>Section 2</h1> 
 

 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    </div> 
 
    <div id="section3" class="container-fluid"> 
 
    <h1>Section 3</h1> 
 

 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    </div> 
 
    <div id="section4" class="container-fluid"> 
 
    <h1>Section 4</h1> 
 

 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p> 
 
    </div> 
 
</body>

Смежные вопросы