I am desperately trying to change the background color of the Bootstrap 5.3 dropdown menu whose link is active.
When I am on a page, the menu link for that page appears in bold, but when that page is contained in the dropdown menu, the menu link has a blue (primary) background, which does not match my theme, and I would like to change it.
When I test different CSS code, I can change the color when I hover over it with my mouse, as well as when I click on it, but the link turns blue again when I am on the page.
Here's my html:
<a class="navbar-brand" href="index.php">
Title
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav text-center">
<li class="nav-item">
<a class="nav-link<?php if ($nom_fichier == "index") {echo ' active" aria-current="page';} ?>" href="index.php">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link<?php if ($nom_fichier == "qui-suis-je") {echo ' active" aria-current="page';} ?>" href="qui-suis-je.php">Qui suis-je ?</a>
</li>
<li class="nav-item dropdown"> <!-- class="nav-item dropdown" -->
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
sous-menu
</a>
<ul class="dropdown-menu text-center">
<li><a class="dropdown-item<?php if ($nom_fichier == "allaitement-maternel") {echo ' active" aria-current="page';} ?>" href="allaitement-maternel.php">allaitement maternel</a></li>
</ul>
</li>
</ul>
</div>
And my css:
.navbar-nav > li > .dropdown-menu a:focus,
.navbar-nav > li > .dropdown-menu a:hover,
.navbar-nav > li > .dropdown-menu a:active {background-color: #FF0000; }
And here the result when I over the menu "Massage bébé":