Skip to content Skip to sidebar Skip to footer

Bootstrap Navbar Covers Top Of Section When Linked

I've been working on my first website for learning purposes and run into this problem: Whenever I link to a specific place on the same page it opens up as intended but the top is c

Solution 1:

This might help or give you some ideas; you're essentially just using two navbars together under a navbar-fixed-top class so they're then together on scroll.

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;
  }
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"rel="stylesheet" /><bodydata-spy="scroll"data-target="#myNavbar"data-offset="100"><navclass="navbar navbar-default navbar-custom navbar-fixed-top"id="myNavbar"><divclass="container"><!-- Brand and toggle get grouped for better mobile display --><divclass="navbar-header"><buttontype="button"class="navbar-toggle collapsed"data-toggle="collapse"data-target="#bs-example-navbar-collapse-1"aria-expanded="false"><spanclass="sr-only">Toggle navigation</span><spanclass="icon-bar"></span><spanclass="icon-bar"></span><spanclass="icon-bar"></span></button><aclass="navbar-brand"href="#">Brand</a></div><!-- Collect the nav links, forms, and other content for toggling --><divclass="collapse navbar-collapse"id="bs-example-navbar-collapse-1"><ulclass="nav navbar-nav navbar-right"><liclass="active"><ahref="#section1">Home</a></li><li><ahref="#section2">About</a></li><li><ahref="#section3">Portfolio</a></li><li><ahref="#section4">Contact</a></li></ul></div><!-- /.navbar-collapse --></div><!-- /.container-fluid --><navclass="navbar navbar-default nav-lower"><divclass="navbar-header"><buttontype="button"class="navbar-toggle collapsed"data-toggle="collapse"data-target="#bs-lower-nav"aria-expanded="false"><spanclass="sr-only">Toggle navigation</span><spanclass="glyphicon glyphicon-chevron-down"></span></button></div><divclass="collapse navbar-collapse"id="bs-lower-nav"><ulclass="nav navbar-nav"><li><ahref="#"><spanclass="glyphicon glyphicon-chevron-left"></span> Facebook
              <spanclass="glyphicon glyphicon-chevron-right"></span></a></li><li><ahref="#"><spanclass="glyphicon glyphicon-chevron-left"></span> GitHub
              <spanclass="glyphicon glyphicon-chevron-right"></span></a></li><li><ahref="#"><spanclass="glyphicon glyphicon-chevron-left"></span> LinkedIn
               <spanclass="glyphicon glyphicon-chevron-right"></span></a></li></ul></div></nav></nav><divid="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><divid="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><divid="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><divid="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>

Post a Comment for "Bootstrap Navbar Covers Top Of Section When Linked"