Bootstrap Navigation Bar With Multi-Level Dropdowns

This tutorial we will teach you how to construct or create a responsive Bootstrap Navigation Bar With Multi-Level Dropdowns. With Bootstrap, a navigation bar can extend or collapse, depending on the screen size. A standard navigation bar is created with a class called "navbar navbar-default". Navigation bars can also hold multiple dropdown menus. And it has a simple HTML page or Web Template by using bootstrap.

Sample Code

Index.php - This is the code for a fix navigation bar and the for the multi-level dropdown.
  1. <div class="container">
  2. <nav class="navbar navbar-default navbar-fixed-top">
  3. <div class="container-fluid">
  4. <div class="navbar-header">
  5. <a class="navbar-brand" href="#">Sourcecodester</a>
  6. </div>
  7. <ul class="nav navbar-nav">
  8. <li class="active"><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
  9. <li><a href="#">HTML</a></li>
  10. <li><a href="#">CSS</a></li>
  11. <li><a href="#">JAVASCRIPT</a></li>
  12. <li><a href="#">PHP</a></li>
  13. <li><a href="#">SQL</a></li>
  14. <li class="dropdown">
  15. <a class="dropdown-toggle" data-toggle="dropdown" href="#">TUTORIAL<span class="caret"></span></a>
  16. <ul class="dropdown-menu">
  17. <li><a href="#">HTML/CSS</a></li>
  18. <li><a href="#">JAVASCRIPT</a></li>
  19. <li><a href="#">PHP</a></li>
  20. <li>
  21. <a class="test" tabindex="-1" href="#">SERVER SIDE <span class="caret"></span></a>
  22. <ul class="dropdown-menu">
  23. <li><a tabindex="-1" href="#">SQL</a></li>
  24. <li><a tabindex="-1" href="#">ASP.NET</a></li>
  25. <li>
  26. <a class="test" href="#">WEB BUILDING <span class="caret"></span></a>
  27. <ul class="dropdown-menu">
  28. <li><a href="#">WEB TEMPLATES</a></li>
  29. <li><a href="#">WEB STATISTICS</a></li>
  30. </ul>
  31. </li>
  32. </ul>
  33. </li>
  34. </ul>
  35. </li>
  36. </ul>
  37. <ul class="nav navbar-nav navbar-right">
  38. <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
  39. <li><a href="#"><span class="glyphicon glyphicon-search"></span></a></li>
  40. </ul>
  41. </div>
  42. </nav>
  43. </div>
For the dropdown menu script to create a multi-level dropdown list.
  1. <script>
  2. $(document).ready(function(){
  3. $('.dropdown a.test').on("click", function(e){
  4. $(this).next('ul').toggle();
  5. e.stopPropagation();
  6. e.preventDefault();
  7. });
  8. });
  9. </script>
result
And for the content of the web page or the html form. This content has a glyphicon effects using a simple script of javascript to make it more responsive.
  1. <div class="content">
  2. <div class="jumbotron text-center">
  3. <h1>SOURCECODESTER</h1>
  4. <p>We Are Specialized In Programming</p>
  5. <form class="form-inline">
  6. <input type="email" class="form-control" size="50" placeholder="Email Address" required>
  7. <button type="button" class="btn btn-danger">Subscribe</button>
  8. </form>
  9. </div>
  10. <div id="about" class="container-fluid">
  11. <div class="row">
  12. <div class="col-sm-8">
  13. <h2>About Sourcecodester</h2><br>
  14. <h4>Lorem ipsum dolor sit amet, consectetur adipiscing 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.</h4><br>
  15. <p>Lorem ipsum dolor sit amet, consectetur adipiscing 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. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing 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.</p>
  16. </div>
  17. <div class="col-sm-4">
  18. <span class="glyphicon glyphicon-globe logo slideanim"></span>
  19. </div>
  20. </div>
  21. </div>
  22.  
  23.  
  24. <div id="services" class="container-fluid text-center">
  25. <h2>SERVICES</h2>
  26. <h4>What we offer</h4>
  27. <br>
  28. <div class="row slideanim">
  29. <div class="col-sm-4">
  30. <span class="glyphicon glyphicon-off logo-small"></span>
  31. <h4>POWER</h4>
  32. </div>
  33. <div class="col-sm-4">
  34. <span class="glyphicon glyphicon-heart logo-small"></span>
  35. <h4>LOVE</h4>
  36. </div>
  37. <div class="col-sm-4">
  38. <span class="glyphicon glyphicon-lock logo-small"></span>
  39. <h4>JOB DONE</h4>
  40. </div>
  41. </div>
  42. <div class="col-sm-4">
  43. <span class="glyphicon glyphicon-leaf logo-small"></span>
  44. <h4>GREEN</h4>
  45. </div>
  46. <div class="col-sm-4">
  47. <span class="glyphicon glyphicon-certificate logo-small"></span>
  48. <h4>CERTIFIED</h4>
  49. </div>
  50. <div class="col-sm-4">
  51. <span class="glyphicon glyphicon-wrench logo-small"></span>
  52. <h4 style="color:#303030;">HARD WORK</h4>
  53. </div>
  54. </div>
  55. </div>
  56.  
  57. <footer class="container-fluid text-center"><hr/>
  58. <p><a href="http://www.sourcecodester.com" title="">www.sourcecodester.com</a></p>
  59. </footer>
  60.  
  61. <script>
  62. $(document).ready(function(){
  63. $(".navbar a, footer a[href='#myPage']").on('click', function(event) {
  64. if (this.hash !== "") {
  65. event.preventDefault();
  66. var hash = this.hash;
  67. $('html, body').animate({
  68. scrollTop: $(hash).offset().top
  69. }, 900, function(){
  70. window.location.hash = hash;
  71. });
  72. }
  73. });
  74.  
  75. $(window).scroll(function() {
  76. $(".slideanim").each(function(){
  77. var pos = $(this).offset().top;
  78.  
  79. var winTop = $(window).scrollTop();
  80. if (pos < winTop + 600) {
  81. $(this).addClass("slide");
  82. }
  83. });
  84. });
  85. })
  86. </script>
  87. </div>
  88. </body>
  89. </html>
Hope that you like my tutorial. And don't forget to Like and Share this to your friends. Enjoy Coding.

Add new comment