How do I apply a hover effect on an a
element, but not to an a
element with the class active
?
a:hover(not: .active)
Seems something is missing.
CSS – Div class hover Hover effect can be directly given to the elements but when it is applied to a particular element like div then the hover effect will be reflected to all the div elements. Using a class to apply the hover effect, gives us a choice to apply it on selective elements.
The :hover selector CSS pseudo-class is used to style elements when the mouse hovers over them. It can be used on every element.
The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).
To solve the issue, you need to go over the CSS hover code to establish if you use the right selector. As well, ensure you use an opening curly bracket ({) after each selector and a closing curly bracket (}) at the end of the property list.
The functional notation is on :not()
, not :hover
:
a:not(.active):hover
If you prefer to put :hover
first, that's fine:
a:hover:not(.active)
It doesn't matter which pseudo-class comes first or last; either way, the selector works the same. It just happens to be my personal convention to put :hover
last as I tend to place user-interaction pseudo-classes behind structural pseudo-classes.
You have the option of using the not()
selector.
a:not(.active):hover { ... }
However, this may not work in all browsers, as not all browsers implement CSS3 features.
If you are targeting a large audience and want to support older browsers, the best way would be to define a style for the .active:hover
and undo whatever you're doing in a:hover
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With