html5 - Can't figure out why Bootstrap Scrollspy isn't working -


i trying implement bootstrap's scroll spy in website isn't working @ all! have tried many things can't work. have lot of custom css being applied navbar not sure if effecting anything. anyways, have far:

html code:

body:

<body id="home" data-spy="scroll" data-target=".navbar" data-offset="0"> 

navbar:

<nav id="navbar" class="navbar navbar-lg navbar-fixed-top hidden-xs-down">     <!-- navbar content -->     <ul class="navul">         <li class="nav-item navitem"><a class="nav-link navhref" href="#home">home</a></li>         <li class="navitem"><a class="navhref" href="#about">about</a></li>         <li class="navitem"><a class="navhref" href="#projects">projects</a></li>         <li class="navitem"><a class="navhref" href="#contact">contact</a></li>     </ul>     <h2>harish</h2>  </nav> 

the section of website:

<div class="sections container-fluid">     <h1 id="about" class="section-heading">about</h1>     <img class="about-img" src="img/harish.jpeg" alt="harish's picture">     <p class="paragraph">text me.</p> </div> 

css code: (just in case of styling interfering bootstrap's scrollspy.)

/*navbar*/  .navbar {   background-color: #009fff;   color: #fff; }  .navbar-lg {   display: -webkit-box;   display: -webkit-flex;   display: -ms-flexbox;   display: flex;   -webkit-box-pack: justify;   -webkit-justify-content: space-between;   -ms-flex-pack: justify;   justify-content: space-between;   -webkit-align-content: center;   -ms-flex-line-pack: center;   align-content: center;   padding: 0; }  .navbar-lg ul {   display: -webkit-box;   display: -webkit-flex;   display: -ms-flexbox;   display: flex;   margin: 0;   margin-right: auto;   -webkit-box-align: center;   -webkit-align-items: center;   -ms-flex-align: center;   align-items: center;   width: auto; }  .navbar-lg ul li {   margin: 0; }  .navbar-lg h2 {   padding: 0;   vertical-align: center;   font-family:  'helvetica neue', 'raleway', 'arial', sans-serif;   font-size: 1.5rem;   vertical-align: center;   margin: 1.5rem;   font-weight: 400; }  .navul {   width: 100%;   display: block;   -webkit-box-pack: center;   -webkit-justify-content: center;   -ms-flex-pack: center;   justify-content: center;   list-style-type: none;   padding-left: 0; }  .navitem {   display: block;   margin: auto;   padding: 0.75rem;   text-align: center;   color: #fff;   font-family: 'raleway', 'helvetica neue', 'arial', sans-serif;   font-size: 1.25rem;   font-weight: 300; }  .navhref {   color: #fff; }  .navhref {   text-decoration: none !important; }  .navhref:visited {   color: #fff; }  .navitem:hover, .navhref:hover {   color: #007bc6; }  .navlinks {   display: -webkit-box;   display: -webkit-flex;   display: -ms-flexbox;   display: flex;   -webkit-box-pack: center;   -webkit-justify-content: center;   -ms-flex-pack: center;   justify-content: center;   color: #009fff; } 

your <ul> missing class="nav"

both elements have required classname:

  • <nav class="navbar">
  • <ul class="nav">

your css overriding bootstrap.css, think want different nav type.

if take @ fiddle: http://jsfiddle.net/n9s3k0ys/2/, you'll note nav not maintain highlighting navigate through page.

upon changing nav class navbar navbar-inverse navbar-fixed-top, you'll see closer you're going for, but... http://jsfiddle.net/n9s3k0ys/3/

upon removing css, becomes more clear: http://jsfiddle.net/n9s3k0ys/4/


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo