Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap collapsible navbar starts open

I am working on a website with bootstrap, this is the code relative to the navbar

<nav id="navi" role="navigation" class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" class="navbar-toggle"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="#" class="navbar-brand">Brand</a>
    </div>
    <div id="bs-example-navbar-collapse-1" class="collapse-navbar-collapse">
      <ul class="nav navbar-nav">
        <li><a href="#" class="active">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Gallery</a></li>
        <li><a href="#">Promotion</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

it look very well both on desktop and on mobile, but the problem is that on mobile, the #bs-example-navbar-collapse-1 element starts open!! so that means that basically I need to press the three lines button 2 times to close it (first click basically re-opens the collapsible)

Anyone had the same issue? Thanks in advance.

like image 254
user3721031 Avatar asked Jan 21 '26 10:01

user3721031


1 Answers

Try

<div id="bs-example-navbar-collapse-1" class="collapse-navbar collapse">

and see if that works. I'm pretty sure it should be two classes like "collapse-navbar collapse" not "collapse-navbar-collapse"

like image 187
joshhunt Avatar answered Jan 24 '26 03:01

joshhunt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!