Home >Web Front-end >CSS Tutorial >Why Doesn\'t :active Work on Anchor Tags in Mobile Safari and How Can I Fix It?

Why Doesn\'t :active Work on Anchor Tags in Mobile Safari and How Can I Fix It?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-02 08:52:10168browse

Why Doesn't :active Work on Anchor Tags in Mobile Safari and How Can I Fix It?

Pseudo-Class :active Not Recognized in Mobile Safari

Certain pseudo-classes, such as :active, are essential for styling elements based on their state. However, in Webkit-based browsers like Safari on iOS devices, applying :active to anchor tags ( tags) doesn't activate when the element is tapped.

Solution:

The body tag contains a crucial attribute that resolves this issue:

<body ontouchstart="">

This attribute enables touch event handling on the body element, which allows the browser to recognize and apply the :active pseudo-class effectively.

Alternatively, you can implement the Fastclick.js library, which enhances click event handling on touch devices and automatically addresses this issue.

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

Statement:
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