Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable dropdown on hover for bootstrap when navbar is collapsed

I have implemented the css as shown here: How to make twitter bootstrap menu dropdown on hover rather than click

However want to disable the dropdown on hover when the navbar collapses as it acts a bit buggy.

How can I do it?

like image 646
Campbell King Avatar asked Feb 16 '13 06:02

Campbell King


People also ask

How can change dropdown from click to hover 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.

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 you prevent the dropdown from closing by 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 do you make a dropdown visible on hover?

Example ExplainedUse any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


1 Answers

You could try wrapping the CSS to disable the dropdown in a media query so that it is only disabling it at a certain page width... Reading up on media queries and trying to understand how bootstrap implements them is going to be one the keys to debugging this. Here's what I tried with the previous answer's fiddle.

http://jsfiddle.net/2Smgv/5544/

@media (min-width: 767px) {
 .sidebar-nav {
    padding: 9px 0;
}

.dropdown-menu .sub-menu {
    left: 100%;
    position: absolute;
    top: 0;
    visibility: hidden;
    margin-top: -1px;
}

.dropdown-menu li:hover .sub-menu {
    visibility: visible;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.nav-tabs .dropdown-menu, .nav-pills .dropdown-menu, .navbar .dropdown-menu {
    margin-top: 0;
}

.navbar .sub-menu:before {
    border-bottom: 7px solid transparent;
    border-left: none;
    border-right: 7px solid rgba(0, 0, 0, 0.2);
    border-top: 7px solid transparent;
    left: -7px;
    top: 10px;
}
.navbar .sub-menu:after {
    border-top: 6px solid transparent;
}
}
like image 130
Ben Avatar answered Sep 20 '22 01:09

Ben