"bootstrap 4 hover dropdown in desktop click on mobile"
Bootstrap 4.1.1 Snippet by soumen

<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/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <nav class="navbar navbar-expand-md bg-dark navbar-dark"> <a class="navbar-brand" href="#">Navbar</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="collapsibleNavbar"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown"> Dropdown link </a> <div class="dropdown-menu"> <a class="dropdown-item" href="#">Link 1</a> <a class="dropdown-item" href="#">Link 2</a> <a class="dropdown-item" href="#">Link 3333 </a> </li> </a> </div> </li> </ul> </div> </nav>
.dropdown-menu::before { content: ''; display: inline-block; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 7px solid #ccc; border-bottom-color: #fff; border-bottom-color: #fff; position: absolute; top: -7px; left: 9px; }
$(document).ready(function() { function toggleNavbarMethod() { if ($(window).width() > 768) { $('.navbar .dropdown').on('mouseover', function(){ $('.dropdown-toggle', this).trigger('click'); }).on('mouseout', function(){ $('.dropdown-toggle', this).trigger('click').blur(); }); } else { $('.navbar .dropdown').off('mouseover').off('mouseout'); } } toggleNavbarMethod(); $(window).resize(toggleNavbarMethod); });

Related: See More


Questions / Comments: