The issue I am having is that I have added a dropdown menu inside of my navigation bar for my site that uses bootstrap, and cannot figure out why the dropdown opens as the default state when the site opens. I am new to bootstrap. I have attached the code for the navbar below:
<div class="navbar navbar-inverse">
<ul class="nav nav-pills pull-right">
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle">
<span class="glyphicon glyphicon-list"></span>
</a>
<ul role="menu" class="dropdown-menu">
<li><a>Add New Item</a></li>
<li><a>PC Requests</a></li>
<li><a>Kit Building</a></li>
</ul>
</li>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Audit</a></li>
<li><a href="#">Check-Out</a></li>
<li><a href="#">Check-In</a></li>
</ul>
<h3 class="text-muted"><span class="glyphicon glyphicon-eye-open"></span> Gentex Vision IVMS</h3>
</div>
Any help would be greatly appreciated!
Set toggle={false} property inside DropdownItem to prevent dropdown from closing.
Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.
Why is my drop down menu not working in bootstrap? Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.
Given the following (copied from Bootstrap), line #13 contains: class="dropdown-menu show". The dropdown menu is displayed on each successive page load. Remove the word show to prevent this behavior.
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#profile">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown show">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="true">Dropdown</a>
<div class="dropdown-menu show" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 39px, 0px);">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</li>
</ul>
Hope this helps.
The point is to add open
to <li class="dropdown">
.
Practically, it should look like this
<div class="navbar navbar-inverse">
<ul class="nav nav-pills pull-right">
<li class="dropdown open">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-list"></span>
</a>
<ul role="menu" class="dropdown-menu">
<li><a>Add New Item</a></li>
<li><a>PC Requests</a></li>
<li><a>Kit Building</a></li>
</ul>
</li>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Audit</a></li>
<li><a href="#">Check-Out</a></li>
<li><a href="#">Check-In</a></li>
</ul>
<h3 class="text-muted"><span class="glyphicon glyphicon-eye-open"></span> Gentex Vision IVMS</h3>
then it will be open by default
Best regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With