I'm trying to apply :hover
only on desktop visitors of a webpage, and :active
on the others. I'm setting the mobile
class to the body
element on the touchscreen devices version, and I put these lines in my css for the buttons in the document (elements with btn
class) :
.btn {
background: blue;
color: white;
border-color: white;
}
:not(.mobile) .btn:hover {
background: red;
color: blue;
border-color: black;
}
.mobile .btn:active {
background: red;
color: blue;
border-color: black;
}
Here is an example of how this mobile webpage could be coded :
<html>
<body class="mobile">
<h1>TITLE</h1>
<div class="btn">button</div>
</body>
</html>
The problem is that when browsing on the mobile page, the :hover pseudo-class is still selected even if the button is a child of the body with the mobile
class ! Am I incorrectly understanding :not(.mobile) .btn:hover
?
I think it should select any immediate/distant element that has the btn
class and is being hovered, and is a child of an element that doesn't have the mobile
class...
I also tried others solutions like media queries, but I couln't get them to work as I expected.
The fiddle : https://jsfiddle.net/162tn8ko/
Thank you for reading my bad english