Home > Web Front-end > CSS Tutorial > How Can I Disable Links Using CSS?

How Can I Disable Links Using CSS?

Barbara Streisand
Release: 2024-12-24 06:38:09
Original
396 people have browsed it

How Can I Disable Links Using CSS?

CSS Trick to Disable Links

Problem:

Is it possible to disable links using CSS? For instance, if you have a class called "current-page," you may want to prevent links with that class from being active when clicked.

Solution:

The following CSS code snippet offers a simple solution:

[aria-current="page"] {
  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: black;
}
Copy after login

This code targets elements with the "aria-current='page'" attribute and disables their interactivity by setting "pointer-events" to "none." It also removes the typical link styling by setting "cursor" to "default," removing text decoration, and resetting the text color to black.

To apply this solution in HTML, you can modify your link as follows:

<a href="link.html" aria-current="page">Link</a>
Copy after login

This will disable the link and prevent it from being clickable when the "current-page" class is applied.

The above is the detailed content of How Can I Disable Links Using CSS?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template