Bootstrap CSS
Bootstrap JS
Jquery
<!DOCTYPE html> <html> <head> <title>Boost your web design skill</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> </head> <body> <div class="body-wrap"> <!-- navbar code start --> <nav class="navbar navbar-inverse"> <div class="container"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbarMenu" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Brand</a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="navbarMenu"> <ul class="nav navbar-nav navbar-right bts-nav"> <li class="active"><a href="#">Home <span class="sr-only">(current)</span></a></li> <li><a href="#">About Us</a></li> <li class="dropdown"> <a href="#" >Services <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li class="dropdown"><a href="#">Another Dropdown <span class="caret dropdown-caret"></span></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Action</a></li> </ul> </li> <li><a href="#">Action</a></li> <li><a href="#">Action</a></li> </ul> </li> <li class="dropdown"><a href="#">Products <span class="caret"></a> <ul class="dropdown-menu"> <li><a href="#">Action</a></li> <li><a href="#">Action</a></li> </ul> </li> <li><a href="#">Contact Us</a></li> </ul> </div> </nav> <!-- navbar code end --> </div> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="main.js"></script> </body> </html>
<style>
.navbar{margin-top:100px;} ul.bts-nav li > ul{ margin-bottom:10px;} .navbar-inverse .navbar-nav>li:hover a{color:#000!important;} .navbar-inverse .navbar-nav>.active>a:hover{color:#fff !important;} .navbar-inverse{border:none!important; border-radius: 0!important;} ul.bts-nav .dropdown-menu{ padding:0px; background: #E7E7E7; border:none; box-shadow: none; border-radius: 0; left:0; } ul.bts-nav li:hover{ background: #E7E7E7; } ul.bts-nav li > ul > li > ul.dropdown-menu { left: 160px; top: -3px; } ul.bts-nav .dropdown-menu>li>a{ padding:10px 20px; } ul.bts-nav .dropdown-caret{ transform: rotate(-90deg); } @media only screen and (max-width: 768px){ ul.bts-nav ul.dropdown-menu { width:100%; position:relative; } ul.bts-nav li > ul > li > ul.dropdown-menu{ left:0; position:relative; } ul.bts-nav .dropdown-caret { transform: rotate(0deg); } }
</style>
<script>
$(document).ready(function(){ var wWidth = $(window).width(); if(wWidth > 768){ $("ul.bts-nav li").hover(function(){ $(this).children("ul").slideToggle(400); }); } else{ $("ul.bts-nav li a").click(function(){ $(this).next("ul").slideToggle(400); }); } }); </script>