YouTip LogoYouTip

Bootstrap4 Dropdowns

The Bootstrap 4 Dropdown is a very common UI component used to display a series of clickable options or menu items. Bootstrap4 dropdowns are typically used in navigation bars, forms, or other interactive interfaces. ### Basic Structure The core of the Bootstrap 4 dropdown is the `.dropdown` class, which can nest other elements (such as buttons, links, or text) to trigger the display of the menu. The menu items themselves are identified using the `.dropdown-menu` class, and specific options use the `.dropdown-item` class. Bootstrap4 dropdowns rely on `popper.min.js`. Style class description: | Class Name | Description | Example Usage | | --- | --- | --- | | `.dropdown` | The container class for the dropdown menu, wrapping the button and menu. | `` | | `.dropdown-toggle` | Used to create a button that triggers the dropdown menu, often used in conjunction with the `.btn` class. | `` | | `data-toggle="dropdown"` | Makes a button or link trigger the display and hiding of the dropdown menu. | `` | | `.dropdown-menu` | The container class for the dropdown menu, containing the menu items. | `` | | `.dropdown-item` | A menu item within the dropdown menu, typically a link. | `Item` | | `aria-haspopup="true"` | Adds accessibility support, indicating that the element has a popup menu. | `` | | `aria-expanded="false"` | Adds accessibility support, indicating the current state of the menu (expanded or collapsed). | `` | Dropdowns are toggleable, contextual menus for displaying lists of links in a list format. ## Example [Try it Β»](#) ### Example Explanation The `.dropdown` class is used to specify a dropdown menu. We can use a button or link to open the dropdown menu. The button or link needs to have the `.dropdown-toggle` and `data-toggle="dropdown"` attributes added. Add the `.dropdown-menu` class to the `
` element to set up the dropdown menu, then add the `.dropdown-item` class to the options within the dropdown menu. We can also use it within an `` tag: ## Example [Try it Β»](#) * * * ## Dividers in Dropdowns The `.dropdown-divider` class is used to create a horizontal divider in the dropdown menu: ## Example [Try it Β»](#) * * * ## Headers in Dropdowns The `.dropdown-header` class is used to add a header in the dropdown menu: ## Example [Try it Β»](#) * * * ## Active and Disabled Items in Dropdowns The `.active` class will highlight a dropdown menu item (adds a blue background). To disable a dropdown menu item, you can use the `.disabled` class. ## Example ActiveDisabled [Try it Β»](#) * * * ## Dropdown Menu Alignment If we want the dropdown menu to be right-aligned, we can add the `.dropdown-menu-right` class after the `.dropdown-menu` class on the element. ## Example
← Bootstrap4 FormsBootstrap4 Progressbars β†’

YouTip © 2024-2026 | Home | Learn Technology, Build Dreams!

All content is for educational and learning purposes only.