I'm using bootstrap for the first time and really liking it - but one thing I'd like to do is have my menu automatically drop down on hover over, rather than having to click the menu title. I'd also like to lose the little arrows next to the menu titles.
432 226 | |||||||||||||||||
|
185 | I created a pure on hover dropdown menu based on the latest (v2.0.2) bootstrap framework that has support for multiple submenus and thought i'd post it for future users: CSS
| ||||||||||||||||||||
|
459 | To get the menu to automatically drop on hover then this can achieved using basic CSS. You need to work out the selector to the hidden menu option and then set it to display as block when the appropriate
To hide the arrow (caret) this is done in different ways depending on whether you are using Twitter Bootstrap version 2 and lower or version 3: Bootstrap 3 To remove the caret in version 3 you just need to remove the HTML
Bootstrap 2 & lower To remove the caret in version 2 you need a little more insight into CSS and I suggest looking at how the
It will work in your favour if you look further into how these work and not just use the answers that I have given you. Thanks to @CocaAkat for pointing out that we were missing the ">" child combinator to prevent sub menus being shown on the parent hover | ||||||||||||||||||||
|
147 | In addition to the answer from "My Head Hurts" (which was great):
There are 2 lingering issues:
The solution to (1) is removing the "class" and "data-toggle" elements from the nav link
This also gives you the ability to create a link to your parent page - which wasn't possible with the default implementation. You can just replace the "#" with whatever page you want to send the user. The solution to (2) is removing the margin-top on the .dropdown-menu selector
| ||||||||||||||||||||
|
66 | I've used a bit of jQuery :::
| ||||||||||||
|
9 | [Update] The plugin is on GitHub and I am working on some improvements (like use only with data-attributes (no JS necessary). I've leaving the code in below, but it's not the same as what's on GitHub. I liked the purely CSS version, but it's nice to have a delay before it closes, as it's usually a better user experience (i.e. not punished for a mouse slip that goes 1 px outside the dropdown, etc), and as mentioned in the comments, there's that 1px of margin you have to deal with or sometimes the nav closes unexpectedly when you're moving to the dropdown from the original button, etc. I created a quick little plugin that I've used on a couple sites and it's worked nicely. Each nav item is independently handled, so they have their own delay timers, etc. JS
The Not pure CSS, but hopefully will help someone else at this late hour (i.e. this is an old thread). If you want, you can see the different processes I went through (in a discussion on the The plugin pattern approach is much cleaner to support individual timers, etc. See the blog post for more. | |||
9 | Simply customize your CSS style in two lines
| ||
6 | There are a lot of really good solutions here. But I thought that I would go ahead and put mine in here as another alternative. It's just a simple jQuery snippet that does it the way bootstrap would if it supported hover for dropdowns instead of just click. I've only tested this with version 3 so I don't know if it would work with version 2. Save it as a snippet in your editor and have it at the stroke of a key.
Basically, It's just saying when you hover on the dropdown class, it will add the open class to it. Then it just works. When you stop hovering on either the parent li with the dropdown class or the child ul/li's, it removes the open class. Obviously, this is only one of many solutions, and you can add to it to make it work on only specific instances of .dropdown. Or add a transition to either parent or child. | ||||||||
|
5 | Even better with jQuery:
| ||||||||
|
5 | I've managed it as follows :
hope this helps someone... | |||
4 | Just want to add, that if you have multiple dropdowns (as I do) you should write:
And it'll work properly. | ||||
|
4 | The best way of doing it is to just trigger bootstraps click event with a hover. This way, it should still remain touch device friendly
| ||
3 | This is probably a stupid idea, but to just remove the arrow pointing down, you can delete the
This does nothing for the up pointing one, though.. | ||
3 | i my opinion the best way is like this.
sample markup:
| ||||
|
3 | Also added margin-top:0 to reset the bootstrap css margin for .dropdown-menu so the menu list dosen't dissapear when the user hovers slowly from drop down menu to the menu list.
| ||||
|
2 | This will hide the up ones
| ||
2 | Jquery solution is good but it will need to either deal with on click events (for mobile or tablet) as hover won't work properly... Could maybe do some window re-size detection? Andres Ilich's answer from above seems to work well but should be wrapped in a media query:
| ||
2 | This works for Wordpress Bootstrap
| |||
2 | This should hide the drop downs and their carets if they are smaller than a tablet.
| |||
1 | So you have this code:
Normally it works on click event, and you want it work on hover event. This is very simple, just use this javascript/jquery code:
This works very well and here is the explanation: we have a button, and a menu. When we hover the button we display the menu, and when we mouseout of the button we hide the menu after 100ms. If you wonder why i use that, is because you need time to drag the cursor from the button over the menu. When you are on the menu, the time is reset and you can stay there as many time as you want. When you exit the menu, we will hide the menu instantly without any timeout. I've used this code in many projects, if you encounter any problem using it, feel free to ask me questions. | ||
1 | If you have an element with a
then you can have the dropdown menu to be automatically drop down on hover over, rather than having to click its title, by using this snippet of jQuery code:
here is a Demo This answer relied on @Michael answer, I have made some changes and added some additions to get the dropdown menu work properly | ||||
0 | Overwrite bootstrap.js with this script.
| ||
0 | Here's my technique that adds a slight delay before the menu is closed after you stop hovering on the menu or the toggle button. The
| ||
0 | We saw, In addition to the answer from "My Head Hurts", "Cory Price" found out 2 problems
The solution was nearly perfect,but the problem here is, when it comes to mobile devices and tablets, it won't work! I'm using a bit of jquery to fix this..
| ||||
|
protected by Community♦ Apr 14 '12 at 19:04
Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged css drop-down-menu twitter-bootstrap or ask your own question.
来自 http://stackoverflow.com/questions/8878033/how-to-make-twitter-bootstrap-menu-dropdown-on-hover-rath...