Using a list-group, the order class works fine but it is not working when I tried using it under the dropdown-menu. Saw the docs in bootstrap 5 about ordering of classes but can’t make it to work inside the dropdown-menu.
See code sample below:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<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 order-5" href="#">Last</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item order-1" href="#">Should be first</a></li>
</ul>
</div>
Anyone experienced this problem?
2
Answers
The "order" class is part of Bootstrap’s Flexbox utilities, the list-group class is creating a flexbox from your
<ul>
element, but dropdown-menu is not, and this is why ordering don`t work with dropdown-menu. But with a little modification you can order the dropdown-menu too.With this modification the
<li>
elements are inside a flexbox, and "order" class can work now.If you want to sort order using
.order-*
class, the parent element should a flexbox. Here is how you can use that sort orderyou need to write additional CSS because when dropdown-menu is showing the class
.dropdown-menu.show
isdisplay: block