Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled dropdown menu items using twitter bootstrap

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?

like image 485
codeape Avatar asked Mar 13 '12 10:03

codeape


People also ask

How do I toggle a dropdown in Bootstrap?

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.

How do I turn off toggle drop down?

To disable to dropdown item in Bootstrap, use the . disabled class with the . dropdown-menu class.

How do I stop dropdown menu Close menu items on clicking inside?

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() .

How can create hover dropdown in Bootstrap?

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.


2 Answers

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

like image 102
Aeomer Avatar answered Sep 21 '22 18:09

Aeomer


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

like image 35
Andres Ilich Avatar answered Sep 22 '22 18:09

Andres Ilich