0

I want to make my hover color override my active class color.

Here is my hover:

.tabs nav a:hover {
    box-shadow: inset 0 -2px #1E528A;
}

here is my active li class:

.tabs nav li.active a {
    box-shadow: inset 0 -2px #3792F5;
}

When I hover over my active class color takes precedence. I want the hover to take precedence over my active class color when hovered over. How can I do this?

lion_bash
  • 888
  • 1
  • 7
  • 19

3 Answers3

0

You have a specificity problem. Typically this is solved by using class names on the target element itself instead of "let's traverse all the way down the DOM" selectors like .tabs nav li.active a. Therefore, to fix this problem you could add a class name, like .navigation-link to each of the <a> elements. One popularly recommended CSS methodology that avoids this problem is BEM. Take a look at this question: Points in CSS specificity

Hatchet
  • 4,880
  • 1
  • 29
  • 42
0

You can simply do this:

.tabs nav a:hover,
.tabs nav li.active a:hover {
    box-shadow: inset 0 -2px #1E528A;
}

or use important:

.tabs nav a:hover {
    box-shadow: inset 0 -2px #1E528A !important;
}

Hope it helps.


Irandoust
  • 520
  • 4
  • 11
0

You can do this:

.tabs nav li.active a:hover {
    box-shadow: inset 0 -2px #3792F5;
}

It should work, but it's too generic and you need to specify all the nested selectors. As suggested in a comment, you can use a descriptive class name, somethink like:

a.menuLink:hover {
   box-shadow: inset 0 -2px #3792F5;
}

In this way you only need to target your a element with the right class.

Finally, avoid using !important, it's a bad practice. You should use !important only when you don't have any other options, and this is not the case.

Damian Peralta
  • 1,696
  • 5
  • 11