How to make a Bootstrap 3 dropdown menu open by default when it is inside a collapsed navbar

后端 未结 4 2060
挽巷
挽巷 2020-12-31 02:55

I\'m trying to make my dropdown menu open by default when my collapsed navbar is opened. Here is a fiddle to show my code so far.

Currently, if you

4条回答
  •  温柔的废话
    2020-12-31 03:18

    According to the docs for Bootstrap v3, you can use Javascript to hook on the collapse events:

    $(function () {
      $('#bs-example-navbar-collapse-1').on('shown.bs.collapse', function(e) {
        $('#my_dropdown').dropdown('toggle', 'open').hide();
        console.log('shown:', e);
      });
    });
    

    I'm not sure the result is what you want, because while the "toggle" button is hidden, the submenu is still indented. Instead of trying to bend Bootstrap that much, perhaps a better solution is having 2 menus with the desired structure for each screen size and show one or another based on media queries.

    Fiddle: http://jsfiddle.net/scardine/tw82o88y/

提交回复
热议问题