I am currently working on customizing a Bootstrap navigation bar using CSS to ensure that the shopping cart icon remains on the right side of the bar on both desktop and mobile devices. Despite my efforts to arrange the elements in various ways, the CSS "order" property does not seem to have any effect.
Below is the mobile navigation bar with the desired layout: https://i.sstatic.net/J9YEf.png
And this is the desktop navigation bar configuration that is not correct: https://i.sstatic.net/pTV0E.png
Here is the code snippet I am using:
@media (min-width: 576px) {
nav #nav-cart {
order: 3;
}
nav #nav-menu {
order: 2;
}
.nav-item {
margin-bottom: -4px;
}
}
nav {
background-color: #a8d0b2;
border-bottom: 1px solid #e5e5e5;
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
flex: auto;
font: lighter 1.5rem 'Buxton Sketch', sans-serif;
}
nav #nav-cart {
order: 2;
}
nav #nav-cart img {
max-height: 32px;
}
nav #nav-header {
order: 1;
}
nav #nav-menu {
order: 3;
}
nav #nav-toggle {
order: 0;
}
.navbar-brand {
font-size: 22px;
white-space: normal;
text-align: center;
word-break: break-all;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="593b36362d2a2d2b3829196c776a776a">[email protected]</a>/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c4f435e496c1e021d1d0214">[email protected]</a>/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22404d4d56515650435262170c110c11">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light mb-3">
<div class="container">
<button id="nav-toggle" class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a id="nav-header" class="navbar-brand" asp-area="" asp-page="/Index">
<img alt="Home" src="placeholder.webp" />
</a>
<a id="nav-cart" class="nav-item nav-link text-light" asp-area="" asp-page="/Cart">
<img alt="Cart" src="assets/shopping_cart_25x24.webp" />
</a>
<div id="nav-menu" class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-page="/Shop">Shop</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" asp-area="" asp-page="/About">About</a>
</li>
</ul>
</div>
</div>
</nav>
Is there a mistake in my implementation, or is there a specific reason why it is not working as intended?