0

I have a nav bar and I would like for the a links to change color when I hover over them but for some reason, even though I used the :hover selector, it still won't work. Can anyone please help me?

<header>
      <nav class="navbar navbar-expand-lg navbar-dark static-top my-navbar my-navbar">
        <div class="container">
          <button`enter code here`
            class="navbar-toggler"
            type="button"
            data-toggle="collapse"
            data-target="#navbarResponsive"
            aria-controls="navbarResponsive"
            aria-expanded="false"
            aria-label="Toggle navigation"
          >
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarResponsive">
            <ul class="navbar-nav ml-auto">
              <li class="nav-item active">
                <a class="nav-link" href="#"
                  >Home
                  <span class="sr-only">(current)</span>
                </a>
              </li>
              <li class="nav-item active">
                <a class="nav-link" href="#">About</a>
              </li>
              <li class="nav-item active">
                <a class="nav-link" href="#">Services</a>
              </li>
              <li class="nav-item active">
                <a class="nav-link my-link" href="#">Contact</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
    </header>

This is my CSS:

/* --- Navbar --- */

.my-navbar {
  background: rgba(116, 118, 119, 0.5);
}

ul li a {
  font-family: "Libre Baskerville", serif;
}

a:hover {
    color: black;
}
/* --- Navbar End --- */

2 Answers2

1

Because you are using navbar-dark you have to be very specific in your selector. For example this will do the job with a .navbar-dark.my-navbar without space.

.navbar-dark.my-navbar .navbar-nav .nav-link:hover,
.navbar-dark.my-navbar .navbar-nav .nav-link:focus {
  color: blue;
  background-color: yellow;
}

Edit You mentioned below that you've removed thenavbar-dark. In that case you may style the hamburger button with these selectors. Use the colors you like.

/* the button */
.my-navbar .navbar-toggler {
  background-color: transparent;
  color: rgba(0, 0, 0, 0.5);
  border-color: rgba(0, 0, 0, 0.2);
}

/* the icon in the button - change only 0, 0, 0, 0.5 (rgba color) */
.my-navbar .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%280, 0, 0, 0.5%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
bron
  • 1,457
  • 1
  • 9
  • 18
0

If you are using Bootstrap try putting ' ! important ' in the css code. !important property in CSS means that all subsequent rules on an element are to be ignored, and the rule denoted by !important is to be applied. This rule overrides all previous styling rules ​-- the !important property increases its priority.

Your css code :

.my-navbar {
   background: rgba(116, 118, 119, 0.5) ! important;
}

ul li a {
    font-family: "Libre Baskerville", serif ! important;
}

a:hover {
     color: black ! important;
}
user12137152
  • 732
  • 1
  • 5
  • 14
Isaac.mm
  • 76
  • 6