How To Add Dropdown Submenus To Bootstrap?
-
Alternative Methods
Adapting to Different Bootstrap Versions
Bootstrap 3 Legacy Support
For Bootstrap 3, you need custom CSS to create dropdown submenus. Here's an example:
.dropdown-submenu {
position: relative;
}
.dropdown-submenu > .dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover > .dropdown-menu {
display: block;
}
This CSS places the submenu and shows it on hover.
The HTML structure for nested dropdowns in Bootstrap 3 looks like this:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-submenu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Submenu</a>
<ul class="dropdown-menu">
<li><a href="#">Submenu item 1</a></li>
<li><a href="#">Submenu item 2</a></li>
</ul>
</li>
</ul>
</li>
This structure creates a dropdown with a nested submenu, allowing multi-level navigation in Bootstrap 3.