I have a dropdown menu inside a nav-collapse.
When I reduce the window's width (eg: 700px), the navbar correctly collapses, then I click on btn-navbar to un-collapse it, then I click on the dropdown, but it does not drop down, the menu does not show. If then I collapse and un-collapse again, the dropdown starts working.
The same happens when the window's width is small from the beginning.
It's like the height of the collapsed part was fixed at the beginning, and it doesn't let the dropdown do its thing.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap-responsive.css" />
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Be sure to leave the brand out there if you want it shown -->
<a class="brand" href="#">Project name</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse">
<ul class="nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Anonymous <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>
<a href=''><i class='icon-chevron-right'></i> Login</a>
</li>
<li>
<a href=''><i class='icon-plus'></i> Register</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>
Bootstrap v2.2.0
Firefox 16.0.2
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.
If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false" . If you've set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead.
When you click on the menu item collapse, dropdown menu closed. When you reopen the dropdown menu, the collapse works.
Bootstrap's collapse class exposes a few events for hooking into collapse functionality. This event fires immediately when the show instance method is called. This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).
A lot of people were reporting this as a bug on the repo (eg. Issue #5671, Issue #5890, Issue #6019).
In response to #5671, someone points out that as per the docs on responsive Navbar, when using the class navbar-collapse
you must also include collapse
. Seems that your example suffers from this same (albeit easily overlooked) flaw.
Here's a working example of your code, the only difference being adding the collapse
class:
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