How to make Twitter Bootstrap menu dropdown on hover rather than click

后端 未结 30 2608
小鲜肉
小鲜肉 2020-11-22 02:08

I\'d like to have my Bootstrap menu automatically drop down on hover, rather than having to click the menu title. I\'d also like to lose the little arrows next to the menu t

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:21

    In addition to the answer from "My Head Hurts" (which was great):

    ul.nav li.dropdown:hover ul.dropdown-menu{
        display: block;    
    }
    

    There are 2 lingering issues:

    1. Clicking on the dropdown link will open the dropdown-menu. And it will stay open unless the user clicks somewhere else, or hovers back over it, creating an awkward UI.
    2. There is a 1px margin between the dropdown link, and dropdown-menu. This causes the dropdown-menu to become hidden if you move slowly between the dropdown and dropdown-menu.

    The solution to (1) is removing the "class" and "data-toggle" elements from the nav link

    
         Dropdown
         
    
    

    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

    .navbar .dropdown-menu {
        margin-top: 0px;
    }
    

提交回复
热议问题