Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all hover effects through css

When I come down on touch devices I don't want the hover behavior. Is it possible to disable all hover effects at once for a whole website?

Given that you use Modernizr to detect touch and set the class.

This is what I came up with but it gives a lot of inconsistency:

html.touch *:hover {
    color: inherit !important;
    background: inherit !important;
}

Is there a way to do this with pure CSS? If not, how can it be done with javascript?

like image 247
Simon Dragsbæk Avatar asked Jan 20 '15 15:01

Simon Dragsbæk


People also ask

How do I turn off hover element?

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

What is CSS hover effect?

What is a CSS Hover Effect? A CSS hover effect takes place when a user hovers over an element, and the element responds with transition effects. It is used to mark the key items on the web page and it's an effective way to enhance the user experience.

How do you change the color of hovering in CSS?

To change the color when hovering in CSS, you will use the CSS selector called :hover . The :hover is a CSS pseudo-class that will select the HTML element when the user hovers over with the mouse. The hover selector will work on almost all HTML elements.


2 Answers

Update

This is now supported very decent across all mobile browsers, here is the Can I use link:

html.touch *:hover {
    all:unset!important;
}

Old answer

This is good but not supported very well:

html.touch *:hover {
    all:unset!important;
}

But this has a very good support:

html.touch *:hover {
    pointer-events: none !important;
}

Works flawless for me, it makes all the hover effects be like when you have a touch on a button it will light up but not end up buggy as the initial hover effect for mouse events.

like image 198
Simon Dragsbæk Avatar answered Sep 21 '22 09:09

Simon Dragsbæk


Try the all:unset or all:initial

html.touch *:hover {
    all:unset!important;
}

Support is limited (https://developer.mozilla.org/en-US/docs/Web/CSS/all)

like image 41
Gabriele Petrioli Avatar answered Sep 21 '22 09:09

Gabriele Petrioli