in Education by

How can we create a dropdown menu in Bootstrap?

1 Answer

0 votes
by

To make the menu more attractive with a DropDown list using Bootstrap open up the bootstrap.css file and check out the following Bootstrap CSS class. 

  1. Caret Class
  2. DropDown-Menu Class

1. Using bootstrap CSS class="Caret"

Now first we use the caret class with li tag. The Caret class shows a caret sign. Now open the bootstrap.css file and find the .navbar-inverse class. It looks like this,

  1. .caret   
  2. {  
  3.     displayinline - block;  
  4.     width0;  
  5.     height0;  
  6.     margin - left: 2 px;  
  7.     vertical - align: middle;  
  8.     border - top: 4 px solid;  
  9.     border - right: 4 px solid transparent;  
  10.     border - left: 4 px solid transparent;  
  11. }  

The HTML file looks as in the following,

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
  2. <html>  
  3.   
  4. <head>  
  5.     <title></title>  
  6.     <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>  
  7.     <link href="Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />  
  8.     <script src="Bootstrap/js/bootstrap.min.js" type="text/javascript"></script>  
  9. </head>  
  10.   
  11. <body>  
  12.     <div class="navbar-inverse">  
  13.         <div class="Container">  
  14.             <ul class="navnavbar-nav">  
  15.                 <li><a href="#">Home</a></li>  
  16.                 <li><a href="#about">Technologies</a></li>  
  17.                 <li><a href="#contact">Article</a></li>  
  18.                 <li><a href="#contact">blog</a></li>  
  19.                 <li><a href="#contact">News <b class ="caret"></b></a></li>  
  20.             </ul>  
  21.         </div>  
  22.     </div>  
  23. </body>  
  24.   
  25. </html>  

The HTML will render without Bootstrap as in the following:

main menu

2. Using bootstrap CSS class="DropDown-Menu"


You now need to add the DropDown-Menu class. Now open the bootstrap.css file and find the DropDown-Menu class. It looks like this,

  1. .dropdown - menu  
  2. {  
  3.     positionabsolute;  
  4.     top: 100 % ;  
  5.     left: 0;  
  6.     z - index: 1000;  
  7.     displaynone;  
  8.     floatleft;  
  9.     min - width160 px;  
  10.     padding5 px 0;  
  11.     margin2 px 0 0;  
  12.     font - size14 px;  
  13.     list - style: none;  
  14.     background - color#ffffff;  
  15.     border1 px solid# cccccc;  
  16.     border1 px solid rgba(0000.15);  
  17.     border - radius: 4 px; -  
  18.     webkit - box - shadow: 0 6 px 12 px rgba(0000.175);  
  19.     box - shadow: 0 6 px 12 px rgba(0000.175);  
  20.     background - clip: padding - box;  
  21. }  

The HTML file looks as in the following,

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
  2. <html>  
  3.   
  4. <head>  
  5.     <title></title>  
  6.     <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>  
  7.     <link href="Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />  
  8.     <script src="Bootstrap/js/bootstrap.min.js" type="text/javascript"></script>  
  9.     <script src="Bootstrap/js/bootstrap.min.js" type="text/javascript"></script>  
  10.     <script src="Bootstrap/js/bootstrap.js" type="text/javascript"></script>  
  11. </head>  
  12.   
  13. <body>  
  14.     <div class="navbarnavbar-inverse">  
  15.         <div class="Container">  
  16.             <ul class="navnavbar-nav">  
  17.                 <li><a href="#">Home</a></li>  
  18.                 <li><a href="#about">Technologies</a></li>  
  19.                 <li><a href="#contact">Article</a></li>  
  20.                 <li><a href="#contact">blog</a></li>  
  21.                 <li class="dropdown"><a href="#" class="dropdown-toggle">News <b class="caret"></b></a>  
  22.                     <ul class="dropdown-menu">  
  23.                         <li><a href="#">Home</a></li>  
  24.                         <li><a href="#">Technologies</a></li>  
  25.                         <li><a href="#">Article</a></li>  
  26.                         <li><a href="#">blog</a></li>  
  27.                     </ul>  
  28.                 </li>  
  29.             </ul>  
  30.         </div>  
  31.     </div>  
  32.     <script src="Bootstrap/js/jquery.js" type="text/javascript"></script>  
  33.     <script src="Bootstrap/js/dropdown.js" type="text/javascript"></script>  
  34.     <script type="text/javascript">  
  35.         $(document).ready(function() {  
  36.             $('.dropdown-toggle').dropdown();  
  37.         });  
  38.     </script>  
  39. </body>  
  40.   
  41. </html>  

The HTML will be rendered with Bootstrap as in the following,

sub menu

Related questions

0 votes
    How can you create Fixed Layout with Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you create a web page using Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you give a style to images in Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    How can you get Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain the Bootstrap basic table?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain Bootstrap buttons and its styles....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain the basic structure of the Bootstrap grid....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What are Containers in Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What are the advantages of Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain Bootstrap Grid System....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Explain the use of Bootstrap CSS class="navnav-list"....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Why choose Bootstrap for building websites?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What is Bootstrap?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    What do you understand about Responsive websites?...
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    Which of the following class in Bootstrap is used to create a dropdown menu? .dropdown .select .select-list None of the above...
asked Feb 28, 2021 in Technology by JackTerrance
...