I've always tired of changing navbar
of all my pages, and I've decided to create a file for navbar
and always give include
on the pages to make adding / removing items easier!
But, my question is whether to make a system in PHP
or JavaScript
that can identify the page to set the class 'active'
in <li>
of navbar
corresponding to current page! p>
The NavBar code is as follows:
<div class="container">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
<li class="active clash"><a href="/">Início</a></li>
<li class="clash"><a href="/ferramentas/gerador-de-emblema">Gerador de Emblemas</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</div>
For example, I'm on page HOME
! Let's say that id
of body
is "1"
.
A script could capture this id
and assign the class active
to <li>
to "1"
!