Home >Web Front-end >CSS Tutorial >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!