Bootstrap Navigation Active Not Working For Links -
i used navigation bar bootstrap template, , template one-page layout navigation sliding down rather linking different page.
i tried changing links link different pages, when active class not work stuck on new page without knowing page on (unless read content) because navigation doesn't tell you.
the active class works when link "#services" example, scrolls down , active class works, when put such "index.php" or "index.html", active class no longer work.
anyone know how can fix this?
this navigation bar html:
<nav id="mainnav" class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <!-- brand , toggle grouped better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <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 page-scroll" href="#page-top">start bootstrap</a> </div> <!-- collect nav links, forms, , other content toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav navbar-right"> <li> <a class="page-scroll" href="#about">about</a> </li> <li> <a class="page-scroll" href="#services">services</a> </li> <li> <a class="page-scroll" href="#portfolio">portfolio</a> </li> <li> <a class="page-scroll" href="#contact">contact</a> </li> </ul> </div> <!-- /.navbar-collapse --> </div> <!-- /.container-fluid --> </nav>
ok....so template you're using bootstraps scrollspy function determines active links page. unfortunately takes account anchors on current page , doesn't utilize same css separate pages. here's need do.
any links go external pages need have href of pages name begin with. you'll have add in same class data-target="#page-top"
in order activate active class on pages li.
here's gets little more complicated. on external page you're going have change anchor links first page include index.html before each anchor name. ensure on other pages you're brought same sections when click on them.
also... on external pages you'll want change navbar-brand href index.html when click on you're brand name take homepage instead of top of existing page.
so lets name of external page test.html. index navigation li's this.
<li><a class="page-scroll" href="#about">about</a></li> <li><a class="page-scroll" href="#services">services</a></li> <li><a class="page-scroll" href="#portfolio">portfolio</a</li> <li><a class="page-scroll" href="#contact">contact</a></li> <li><a class="page-scroll" href="test.html" data-target="#page-top">test</a></li>
your test.html navbar brand this
<a class="navbar-brand page-scroll" href="index.html">start bootstrap</a>
and test.html navigation li's this
<li><a class="page-scroll" href="index.html#about">about</a></li> <li><a class="page-scroll" href="index.html#services">services</a></li> <li><a class="page-scroll" href="index.html#portfolio">portfolio</a></li> <li><a class="page-scroll" href="index.html#contact">contact</a></li> <li><a class="page-scroll" href="test.html" data-target="#page-top">test</a></li>
Comments
Post a Comment