htmlcsstwitter-bootstrapdrop-down-menubootstrap-5

How to make active menu item background more visible


How to make this active menu item background blue or darker like in Windows desktop applications menus?

enter image description here

Bootstrap 5 dropdown menu is created using this code (also in JSFiddle):

<!-- Bootstrap 5 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>

<div class="btn-group">
  <button type="button" class="btn btn-danger dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
        Action
      </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#"><u>A</u>ction</a></li>
    <li><a class="dropdown-item" href="#">A<u>n</u>other action</a></li>
    <li><a class="dropdown-item" href="#"><u>S</u>omething else here</a></li>
    <li>
      <hr class="dropdown-divider">
    </li>
    <li><a class="dropdown-item" href="#">S<u>e</u>parated link</a></li>
  </ul>
</div>


Solution

  • You want it to have a different color when it hover. You need to write a style for this. So you can give the color you want here. The code below explains how to change the color of the elements. You can choose the color you want to add.

    <style>
          .dropdown-item:focus, .dropdown-item:hover {
            background-color: blue !important;
            color:white !important;
          }      
      </style>
    

    Demo

    .dropdown-item:focus, .dropdown-item:hover {
                background-color: blue !important;
                color:white !important;
              } 
    <!-- Bootstrap 5 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <div class="btn-group">
      <button type="button" class="btn btn-danger dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
            Action
          </button>
      <ul class="dropdown-menu">
        <li><a class="dropdown-item" href="#"><u>A</u>ction</a></li>
        <li><a class="dropdown-item" href="#">A<u>n</u>other action</a></li>
        <li><a class="dropdown-item" href="#"><u>S</u>omething else here</a></li>
        <li>
          <hr class="dropdown-divider">
        </li>
        <li><a class="dropdown-item" href="#">S<u>e</u>parated link</a></li>
      </ul>
    </div>