Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS disable hover effect

Tags:

css

hover

I need to disable the mouse hover on a particular button(not on all buttons) in the entire DOM. Please let me know how to achieve it using a CSS class.

i am using the below CSS class when my button is disabled. now i want to remove the hover effect using the same class.

.buttonDisabled  {  Cursor:text !important; Text-Decoration: None !important;   }  

The above class will take care of removing the hand sign and text underline on mouse over . Now i want to remove hover effect also. Please let me know.

like image 242
user2681868 Avatar asked Nov 05 '14 10:11

user2681868


People also ask

How do I turn off hover in CSS?

To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.

How do you set hover to none?

One method to do this is to add: pointer-events: none; to the element, you want to disable hover on. (Note: this also disables javascript events on that element too, click events will actually fall through to the element behind ).

How do you remove ignore hover CSS style on touch devices?

You can remove all the CSS rules containing :hover using Javascript. This has the advantage of not having to touch CSS and being compatible even with older browsers. Limitations: stylesheets must be hosted on the same domain (that means no CDNs).


2 Answers

I have really simple solution for this.

just create a new class

.noHover{     pointer-events: none; } 

and use this to disable any event on it. use it like:

<a href='' class='btn noHover'>You cant touch ME :P</a> 
like image 124
Seetpal singh Avatar answered Oct 12 '22 23:10

Seetpal singh


You can achieve this using :not selector:

HTML code:

<a class="button">Click me</a> <a class="button disable">Click me</a> 

CSS code (using scss):

.button {   background-color: red;   &:not(.disable):hover {     /* apply hover effect here */   }    } 

In this way you apply the hover effect style when a specified class (.disable) is not applied.

like image 44
Simone Colnaghi Avatar answered Oct 12 '22 22:10

Simone Colnaghi