dropdown menu in bootstrap code example

Example 1: create a dropdown in html bootstrap

<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenu2">
    <button class="dropdown-item" type="button">Action</button>
    <button class="dropdown-item" type="button">Another action</button>
    <button class="dropdown-item" type="button">Something else here</button>
  </div>
</div>

Example 2: bootstrap dropdown

<!-- Bootstrap 5 Dropdown -->
<div class="dropdown">
   <button
      class="btn btn-secondary dropdown-toggle"
      type="button"
      id="dropdownMenuButton1"
      data-bs-toggle="dropdown"
      aria-expanded="false"
   >
      Dropdown button
   </button>
   <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
      <li><a class="dropdown-item" href="#">Action</a></li>
      <li><a class="dropdown-item" href="#">Another action</a></li>
      <li><a class="dropdown-item" href="#">Something else here</a></li>
   </ul>
</div>

Example 3: dropdown bootstrap

<div class="dropdown show">
  <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown link
  </a>

  <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
    <a class="dropdown-item" href="#">Action</a>
    <a class="dropdown-item" href="#">Another action</a>
    <a class="dropdown-item" href="#">Something else here</a>
  </div>
</div>

Example 4: navbar bootstrap 4 with dropdown

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

Example 5: dropdown forms in bootstrap

<li class="dropdown">
         <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown            

         <b class="caret"></b></a>
         <ul class="dropdown-menu">
           <li><a href="#"><form role="form">
<div class="form-group">
  <label for="sel1">Select list (select one):</label>
  <select class="form-control" id="sel1">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
  </select>
  <br>
  <label for="sel2">Mutiple select list (hold shift to select more than one):</label>
  <select multiple class="form-control" id="sel2">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
  </select>
</div>

Example 6: bootstrap dropdown

.dropdown
Add a simple dropdown menu with buttons.
<div class=”dropdown”>
 <button class=”btn btn-secondary dropdown-toggle”
 type=”button” id=”dropdownMenu1” data-toggle=”dropdown”
 aria-haspopup=”true” aria-expanded=”false”>
 Dropdown
 </button>
 <div class=”dropdown-menu” aria-labelledby=”dropdownMenu1”>
 <a class=”dropdown-item” href=”#!”>Action</a>
 <a class=”dropdown-item” href=”#!”>Another action</a>
 </div>
</div>
.dropdown-toggle-split
Create split button dropdowns with proper spacing around the dropdown caret.
<div class=”btn-group”>
 <button type=”button” class=”btn btn-secondary”>Dropdown</button>
 <button type=”button” class=”btn btn-secondary dropdown-toggle dropdown-togglesplit” data-toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
 <span class=”sr-only”>Toggle Dropdown</span>
 </button>
 <div class=”dropdown-menu”>
 <a class=”dropdown-item” href=”#!”>Action</a>
 <a class=”dropdown-item” href=”#!”>Another action</a>
 </div>
</div>
.dropup
Did you know that you can style a menu coming up rather than down? Now you do!
<!-- Default dropup button -->
<div class=”btn-group dropup”>
 <button type=”button” class=”btn btn-secondary dropdown-toggle” datatoggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
 Dropup
 </button>
 <div class=”dropdown-menu”>
 <!-- Dropdown menu links -->
 </div>
</div>
.dropright
Provide the menu to the right of the button.
 <!-- Default dropright button -->
<div class=”btn-group dropright”>
 <button type=”button” class=”btn btn-secondary dropdown-toggle” datatoggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
 Dropright
 </button>
 <div class=”dropdown-menu”>
 <!-- Dropdown menu links -->
  </div>
</div>
.dropleft
...And you can also display the menu on the left.
<!-- Default dropleft button -->
<div class=”btn-group dropleft”>
 <button type=”button” class=”btn btn-secondary dropdown-toggle” datatoggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
 Dropleft
 </button>
 <div class=”dropdown-menu”>
 <!-- Dropdown menu links -->
 </div>
</div>
.dropdown-item-text
Add non-interactive dropdown items to your menu.
<div class=”dropdown-menu”>
 <span class=”dropdown-item-text”>Plain text</span>
 <a class=”dropdown-item” href=”#”>Clickable action</a>
 <a class=”dropdown-item” href=”#”>Another action</a>
 <a class=”dropdown-item” href=”#”>Whatever else you need</a>
</div>
.dropdown-item disabled
You can also choose to disable any menu item(s).
<div class=”dropdown-menu”>
 <a class=”dropdown-item” href=”#”>Active link</a>
 <a class=”dropdown-item disabled” href=”#”>Disabled link</a>
 <a class=”dropdown-item” href=”#”>One more link</a>
</div>
.dropdown-divider
Add a simple divider between menu elements to draw extra attention.
<div class=”dropdown-divider”></div>
.dropdown-menu-right
Align the entire menu to the right
<div class=”btn-group”>
 <button type=”button” class=”btn btn-secondary dropdown-toggle” datatoggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
 This dropdown’s menu is right-aligned
 </button>
 <div class=”dropdown-menu dropdown-menu-right”>
 <button class=”dropdown-item” type=”button”>Action</button>
 <button class=”dropdown-item” type=”button”>Another action</button>
 <button class=”dropdown-item” type=”button”>Something else here</button>
 </div>
</div>

Tags:

Misc Example