如何禁用仅使用CSS的链接? [英] How to disable a link using only CSS?

查看:84
本文介绍了如何禁用仅使用CSS的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个名为 current-page 的类,并希望与该类的链接处于禁用状态,以便在单击它们时不发生任何操作。 解决方案

答案已在问题的评论。为了获得更多的知名度,我在这里复制此解决方案



.not-active {pointer-events:none;光标:默认;文字修饰:无; color:black;}

 < a href =link .htmlclass =not-active> Link< / a>  

有关浏览器支持,请参阅 https://caniuse.com/#feat=pointer-events 。如果您需要支持IE,则有一种解决方法;请参阅此答案



警告:使用 pointer-events 在非SVG元素的CSS中是实验性的。该功能曾经是CSS3 UI草案规范的一部分,但由于许多未解决的问题,已被推迟到CSS4。


Is there any way to disable a link using CSS?

I have a class called current-page and want links with this class to be disabled so that no action occurs when they are clicked.

解决方案

The answer is already in the comments of the question. For more visibility, I am copying this solution here:

.not-active {
  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: black;
}

<a href="link.html" class="not-active">Link</a>

For browser support, please see https://caniuse.com/#feat=pointer-events. If you need to support IE there is a workaround; see this answer.

Warning: The use of pointer-events in CSS for non-SVG elements is experimental. The feature used to be part of the CSS3 UI draft specification but, due to many open issues, has been postponed to CSS4.

这篇关于如何禁用仅使用CSS的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆