Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Lesson 18: Creating a Dropdown Menu in Bootstrap 5

Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss. Here's how to use dropdown menus in Bootstrap 5.

Table of Contents

Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss. Here's how to use dropdown menus in Bootstrap 5.

Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss. Here's how to use dropdown menus in Bootstrap 5 .

Create a Basic Dropdown Menu

A dropdown menu is a toggleable menu that allows the user to select a value from a predefined list. Essentially, it would look like this:

 

Detailed explanation:

This class .dropdownrepresents a dropdown menu.

To open this menu, use a button or link containing the class .dropdown-toggleand attribute data-bs-toggle="dropdown".

Add a class .dropdown-menuto the element to create a real dropdown menu. Then add the class .dropdown-itemto each element (link or button) inside the dropdown menu.

For example:

 Bootstrap Example 
 

Lesson 18: Creating a Dropdown Menu in Bootstrap 5 screenshot

Split Dropdown Menu

The `.dropdown-divider` class is used to separate the links within a dropdown menu with a thin horizontal border:

For example:

 Bootstrap Example 

Split Dropdown Menu

 

Split Dropdown Menu screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5 (2)

This class .dropdown-headeris used to add headers inside the dropdown menu:

For example:

 Bootstrap Example 
 

Lesson 18: Creating a Dropdown Menu in Bootstrap 5 screenshot (3)

Disabled and Enabled Items

Highlight a specific dropdown item using a class .active(add a blue background color).

To disable an item in a dropdown menu, use the class .disabled(which has light gray text and no mouse cursor effect):

  • Normal
  • Active
  • Disabled

For example:

 Bootstrap Example 

The Dropdown Menu Has Disabled Items Highlighted in Light Gray

 

Lesson 18: Creating a Dropdown Menu in Bootstrap 5 screenshot (4)

Drop-off Location

You can also create a "dropend" (drop-down on the right) or "dropstart" (drop-down on the left) menu by adding the class.dropend or.dropstart to the dropdown element. Note that the caret/arrow is added automatically.

Drop it to the right:

Drop it to the left:

For example:

Menu dropend:

 Bootstrap Example 

Add.dropend next to the dropdown menu to right-align it. Carets and arrows are added automatically;

 

Menu Drop-down Menu screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5 (5)

Dropstart menu:

 Bootstrap Example 

Dropstart Menu

Add.dropstart next to the dropdown menu to align it to the left.

Dropstart Menu screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5 (6)

To the Right of the Dropdown Menu

To align the dropdown menu to the right, add the .dropdown-menu-endfollowing class to this element .dropdown-menu:

 

For example:

 Bootstrap Example 

The Dropdown Menu Is on the Right

 

The Dropdown Menu Is on the Right screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5 (7)

Dropup

If you want the dropdown menu to expand upwards instead of dropping down, change the element with class='dropdown' to 'dropup' ::

 

For example:

 Bootstrap Example 

The `.dropup` class makes the dropdown menu expand upwards instead of downwards:

Note that there must be space for the expandable dropup menu.

Lesson 18: Creating a Dropdown Menu in Bootstrap 5 screenshot (8)

Text Dropdown

The class .dropdown-item-textis used to add plain text to a dropdown menu or to use links for the default link style:

For example:

 Bootstrap Example 
 

The Dropdown Menu Contains Text or a Link screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5

Group Buttons with Dropdown Menus

The basic code is as follows:

   

For example:

 Bootstrap Example 

Nested Button Groups to Create a Dropdown Menu

   

Nested Button Groups to Create a Dropdown Menu screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5

Vertical Button Layout with Dropdown Menu

Basic code:

   

For example:

 Bootstrap Example 

Group the Buttons Vertically with the Dropdown Menu

   

Group the Buttons Vertically with the Dropdown Menu screenshot for Lesson 18: Creating a Dropdown Menu in Bootstrap 5

Above is how to create a dropdown menu using Bootstrap 5. As you can see, it's not too difficult if you take the time to learn a little. Good luck!

FAQ

What is the main point of lesson 18: creating a dropdown menu in bootstrap 5?

Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss. Here's how to use dropdown menus in Bootstrap 5.

Why is this development important?

Key takeaway: Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss.

What are the key takeaways?

Dropdown menus in Bootstrap 5 are a cool feature you shouldn't miss.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.