Keep Bootstrap Dropdown open in Navbar no matter what

后端 未结 2 1414
耶瑟儿~
耶瑟儿~ 2021-01-18 21:07

I have a dropdown menu nested in a navbar that I am opening during page load by adding the open class to the li element containing the dropdown men

相关标签:
2条回答
  • 2021-01-18 21:28

    This uses only css. working demo

    Add a class to the dropdown ul (.stay-open)

    <ul class="dropdown-menu stay-open">
    

    then apply style display block with !important

    .stay-open {display:block !important;}
    
    0 讨论(0)
  • 2021-01-18 21:28

    I am assuming that you are using a bootstrap dropdown, give this a shot:

    $('li.dropdown').on({
        "shown.bs.dropdown": function() { this.close = false; },
        "click":             function() { this.close = true; },
        "hide.bs.dropdown":  function() { return this.close; }
    });
    

    The above implementation will hide the dropdown when it is clicked again. If you do not like that behavior, you can simply remove the first two lines (shown.bs.dropdown and click events) and simply return false for hide.bs.dropdown event.

    Here is working proof bootply

    Here is a working proof bootply that will always stay open

    0 讨论(0)
提交回复
热议问题