Home > Web Front-end > CSS Tutorial > Why Doesn\'t the `:active` Pseudo-class Work on Mobile Safari Links, and How Can I Fix It?

Why Doesn\'t the `:active` Pseudo-class Work on Mobile Safari Links, and How Can I Fix It?

DDD
Release: 2024-12-02 22:17:15
Original
560 people have browsed it

Why Doesn't the `:active` Pseudo-class Work on Mobile Safari Links, and How Can I Fix It?

Solving the Non-Functioning :active Pseudo-Class for :active Links in Mobile Safari

Applying styles to an element using the :active pseudo-class is a common practice for highlighting active links. However, in Webkit on iOS devices, this behavior is not triggered when tapping on the element. To resolve this issue, consider the following solutions:

Touchstart Event

Add the ontouchstart event to the element:

<body ontouchstart="">
    ...
</body>
Copy after login

This enables the trigger of the :active pseudo-class when tapping on any element within the page.

Fastclick Library

Alternatively, utilize the Fastclick JavaScript library. This library enhances the responsiveness of click events on touch devices and also addresses the :active pseudo-class issue.

The above is the detailed content of Why Doesn\'t the `:active` Pseudo-class Work on Mobile Safari Links, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template