I use markup to display a dropdown menu using Twitter Bootstrap.
<ul class="nav pull-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="#">Menu item 1...</a></li> <li class="divider"></li> <li><a href="#">Menu item 2...</a></li> <li><a href="#">Menu item 3</a></li> </ul> </li> </ul>
I want to be able to make menu items appear disabled, i.e. no hover effect and probably a different text decoration to make the disabled state visible to the user.
What is the best way to accomplish this? Is there an exisisting bootstrap css class I can add to the <li>
or <a>
element?
To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. The . caret class creates a caret arrow icon (), which indicates that the button is a dropdown.
To disable to dropdown item in Bootstrap, use the . disabled class with the . dropdown-menu class.
As all Twitter Bootstrap users know, the dropdown menu closes on click (even clicking inside it). To avoid this, I can easily attach a click event handler on the dropdown menu and simply add the famous event. stopPropagation() .
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.
When outputing the code for a disabled drop down, why not simply use :
<li class='disabled'> <a href="#">Menu</a> </li>
You can always add the caret back if you still want it to appear.
Update:
Adding W3Schools Link
You can attach a custom disabled class to your menu link a
tag that you want to disable and simply remove the default action by using preventDefault and targetting that class, like so:
$(".disabled-link").click(function(event) { event.preventDefault(); });
Then you can style all events from the .disabled-link
with a grey backdrop or any style you like;
CSS
a.disabled-link, a.disabled-link:visited , a.disabled-link:active, a.disabled-link:hover { background-color:#d9d9d9 !important; color:#aaa !important; }
Demo
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