"Multi level dropdown menu responsive"
Bootstrap 4.1.1 Snippet by vosidiy

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <header class="section-header py-4"> <div class="container"> <h2>Demo page</h2> </div> </header> <!-- section-header.// --> <div class="container"> <nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <a class="navbar-brand" href="#">Brand</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main_nav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="main_nav"> <ul class="navbar-nav"> <li class="nav-item active"> <a class="nav-link" href="#">Home </a> </li> <li class="nav-item"><a class="nav-link" href="#"> About </a></li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"> Treeview menu </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#"> Dropdown item 1 </a></li> <li><a class="dropdown-item" href="#"> Dropdown item 2 &raquo </a> <ul class="submenu dropdown-menu"> <li><a class="dropdown-item" href="">Submenu item 1</a></li> <li><a class="dropdown-item" href="">Submenu item 2</a></li> <li><a class="dropdown-item" href="">Submenu item 3 &raquo </a> <ul class="submenu dropdown-menu"> <li><a class="dropdown-item" href="">Multi level 1</a></li> <li><a class="dropdown-item" href="">Multi level 2</a></li> </ul> </li> <li><a class="dropdown-item" href="">Submenu item 4</a></li> <li><a class="dropdown-item" href="">Submenu item 5</a></li> </ul> </li> <li><a class="dropdown-item" href="#"> Dropdown item 3 </a></li> <li><a class="dropdown-item" href="#"> Dropdown item 4 </a> </ul> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"> More items </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#"> Dropdown item 1 </a></li> <li><a class="dropdown-item dropdown-toggle" href="#"> Dropdown item 2 </a> <ul class="submenu dropdown-menu"> <li><a class="dropdown-item" href="">Submenu item 1</a></li> <li><a class="dropdown-item" href="">Submenu item 2</a></li> <li><a class="dropdown-item" href="">Submenu item 3</a></li> </ul> </li> <li><a class="dropdown-item dropdown-toggle" href="#"> Dropdown item 3 </a> <ul class="submenu dropdown-menu"> <li><a class="dropdown-item" href="">Another submenu 1</a></li> <li><a class="dropdown-item" href="">Another submenu 2</a></li> <li><a class="dropdown-item" href="">Another submenu 3</a></li> <li><a class="dropdown-item" href="">Another submenu 4</a></li> </ul> </li> <li><a class="dropdown-item dropdown-toggle" href="#"> Dropdown item 4 </a> <ul class="submenu dropdown-menu"> <li><a class="dropdown-item" href="">Another submenu 1</a></li> <li><a class="dropdown-item" href="">Another submenu 2</a></li> <li><a class="dropdown-item" href="">Another submenu 3</a></li> <li><a class="dropdown-item" href="">Another submenu 4</a></li> </ul> </li> <li><a class="dropdown-item" href="#"> Dropdown item 4 </a></li> <li><a class="dropdown-item" href="#"> Dropdown item 5 </a></li> </ul> </li> </ul> <ul class="navbar-nav ml-auto"> <li class="nav-item"><a class="nav-link" href="#"> Menu item </a></li> <li class="nav-item"><a class="nav-link" href="#"> Menu item </a></li> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"> Dropdown right </a> <ul class="dropdown-menu dropdown-menu-right"> <li><a class="dropdown-item" href="#"> Dropdown item 1</a></li> <li><a class="dropdown-item" href="#"> Dropdown item 2 </a></li> <li><a class="dropdown-item dropdown-toggle" href="#"> Dropdown item 3 </a> <ul class="submenu submenu-left dropdown-menu"> <li><a class="dropdown-item" href="">Submenu item 1</a></li> <li><a class="dropdown-item" href="">Submenu item 2</a></li> <li><a class="dropdown-item" href="">Submenu item 3</a></li> <li><a class="dropdown-item" href="">Submenu item 4</a></li> </ul> </li> <li><a class="dropdown-item" href="#"> Dropdown item 4 </a></li> </ul> </li> </ul> </div> <!-- navbar-collapse.// --> </nav> <section class="section-content py-5"> <h6>Demo view: Bootstrap multilevel dropdown menu </h6> <p>For this demo page you should connect to the internet to receive files from CDN like Bootstrap CSS, Bootstrap JS and jQuery. </p> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p> <p> More examples on <a href="http://bootstrap-menu.com/"> Bootstrap-menu.com </a></p> <a href="http://bootstrap-menu.com/multilevel.html" class="btn btn-warning">Back to tutorial or Download code</a> </section> </div><!-- container // -->
@media (min-width: 992px){ .dropdown-menu .dropdown-toggle:after{ border-top: .3em solid transparent; border-right: 0; border-bottom: .3em solid transparent; border-left: .3em solid; } .dropdown-menu .dropdown-menu { margin-left:0; margin-right: 0; } .dropdown-menu li{ position: relative; } .nav-item .submenu{ display: none; position: absolute; left:100%; top:-7px; } .nav-item .submenu-left{ right:100%; left:auto; } .dropdown-menu > li:hover{ background-color: #f1f1f1 } .dropdown-menu > li:hover > .submenu{ display: block; } }
// jquery ready start $(document).ready(function() { // jQuery code //////////////////////// Prevent closing from click inside dropdown $(document).on('click', '.dropdown-menu', function (e) { e.stopPropagation(); }); // make it as accordion for smaller screens if ($(window).width() < 992) { $('.dropdown-menu a').click(function(e){ e.preventDefault(); if($(this).next('.submenu').length){ $(this).next('.submenu').toggle(); } $('.dropdown').on('hide.bs.dropdown', function () { $(this).find('.submenu').hide(); }) }); } }); // jquery end

Related: See More


Questions / Comments: