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?
If you want to sort order using .order-*
class, the parent element should a flexbox. Here is how you can use that sort order
<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 flex-column" aria-labelledby="dropdownMenuButton1">
<li class="order-5"><a class="dropdown-item" href="#">Last</a></li>
<li class="order-1"><a class="dropdown-item" href="#">Another action A</a></li>
<li class="order-1"><a class="dropdown-item" href="#">Another action B</a></li>
<li class="order-0"><a class="dropdown-item" href="#">Should be first</a></li>
</ul>
</div>
.dropdown-menu.flex-column.show {
display: flex;
}
you need to write additional CSS because when dropdown-menu is showing the class .dropdown-menu.show
is display: block