Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an opposite CSS pseudo-class to :hover?

Is there a pseudo-class in CSS to specify

:not(:hover) 

Or is that the only way to specify an item that is not being hovered?

I went through several CSS3 references, and I see no mention of a CSS pseudo-class to specify the opposite of :hover.

like image 642
RockPaperLz- Mask it or Casket Avatar asked Jun 14 '15 22:06

RockPaperLz- Mask it or Casket


People also ask

What is opposite of hover in CSS?

The opposite of :hover appears to be :link .

Can you hover a pseudo element?

To clarify, you CAN NOT give :hover to a pseudo element. There's no such thing as ::after:hover in CSS as of 2018.

Is hover a pseudo selector?

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).

Can I hover a class on CSS?

CSS – Div class hoverHover 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.


1 Answers

Yes, use :not(:hover)

.child:not(:hover){   opacity: 0.3; } 

.child {   display: inline-block;   background: #000;   border: 1px solid #fff;   width: 50px;   height: 50px;   transition: 0.4s; }  .child:not(:hover) {   opacity: 0.3; }
<div class="parent">   <div class="child"></div>   <div class="child"></div>   <div class="child"></div>   <div class="child"></div>   <div class="child"></div> </div>

Another example; I think you want to: "when one is hovered, dim all other elements".

If my assumption is correct, and assuming all your selectors are inside the same parent:

.parent:hover .child{   opacity: 0.2;      // Dim all other elements } .child:hover{   opacity: 1;        // Not the hovered one } 

.child {   display: inline-block;   background: #000;   border: 1px solid #fff;   width: 50px;   height: 50px;   transition: 0.4s; }  .parent:hover .child {   opacity: 0.3; }  .parent .child:hover {   opacity: 1; }
<div class="parent">   <div class="child"></div>   <div class="child"></div>   <div class="child"></div>   <div class="child"></div> </div>

Otherwise... simply use the default logic:

.child{   opacity: 0.2; } .child:hover{   opacity: 1; } 
like image 61
Roko C. Buljan Avatar answered Sep 28 '22 17:09

Roko C. Buljan