Attempting to modify the background color for the navbar menu items on smaller screen sizes.
An issue arises in the following scenario:
- Browser window is resized until hamburger menu appears
- Hamburger menu is clicked to display menu items
(the background color changes as intended)
- The browser window is enlarged until the hamburger menu disappears
At this point, the background color does not return to its original state. Is there a way to fix this?
See the code snippet below for reference:
.navbar-collapse.show,
.navbar-collapse.show .navbar-nav .nav-item .nav-link,
.navbar-collapse.collapse,
.navbar-collapse.collapse .navbar-nav .nav-item .nav-link {
background-color: #000000;
color: #FFFFFF;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
Tried applying style properties to:
.navbar-collapse.collapse,
.navbar-collapse.collapse .navbar-nav .nav-item .nav-link
Unfortunately, that did not resolve the issue.