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
You can add a javascript function to your code:
<script>
$(document).ready(function(){
$(".dropdown").hover(
function() {
$('.dropdown-menu', this).stop( true, true ).slideDown("fast");
$(this).toggleClass('open');
},
function() {
$('.dropdown-menu', this).stop( true, true ).slideUp("fast");
$(this).toggleClass('open');
}
);
});
</script>
you can see the example and demo in dtc-eng
Just remove data-toggle="dropdown"
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/
You can add css style for responsive mobile display. paste it into your css file:
@media only screen and (max-width:480px){
.dropdown-menu{
display: block;
position: static;
background-color:transparent;
border:0 none;
box-shadow:none;
margin-top:0;
position:static;
width:100%;
}
.navbar-nav .dropdown-menu > li > a,
.navbar-nav .dropdown-menu .dropdown-header {
padding:5px 15px 5px 25px;
}
.navbar-nav .dropdown-menu > li > a{
line-height:20px;
}
.navbar-default .navbar-nav .dropdown-menu > li > a{
color:#777;
}
}
you can see it in its entirety here : Demo jsfiddle
hope that helps.