Categories
JavaScript Answers

How to prevent sticky hover effects for buttons on touch devices with CSS?

Spread the love

Sometimes, we want to prevent sticky hover effects for buttons on touch devices with CSS.

In this article, we’ll look at how to prevent sticky hover effects for buttons on touch devices with CSS.

How to prevent sticky hover effects for buttons on touch devices with CSS?

To prevent sticky hover effects for buttons on touch devices with CSS, we can use the hover media query.

For instance, we write

@media (hover: hover) {
  button:hover {
    background-color: blue;
  }
}

to apply styles for the hover media query.

We set buttons’ background color to blue if we’re hovering on a touch screen by using the media query.

Conclusion

To prevent sticky hover effects for buttons on touch devices with CSS, we can use the hover media query.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *