是否有一种方法禁用链接使用CSS?

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


当前回答

你也可以试试这个

<style> .btn-disable { pointer-events: none !important; color: currentColor; cursor: not-allowed; opacity: 0.6; text-decoration: none; } </style> <html> <head> <title>NG</title> </head> <style> .btn-disable { pointer-events: none !important; color: currentColor; cursor: not-allowed; opacity: 0.6; text-decoration: none; } </style> <body> <div class="btn-disable"> <input type="button" value="Show"> </div> </body> </html>

其他回答

您还可以调整另一个元素的大小,使其覆盖链接(使用正确的z-index):这将“吃掉”点击。

(我们偶然发现这一点,因为我们有一个问题,突然不活跃的链接,由于“响应式”设计导致H2覆盖他们时,浏览器窗口的移动大小。)

Bootstrap禁用链接

<a href="#" class="btn btn-primary btn-lg disabled" role="button">Primary link</a>

<a href="#" class="btn btn-default btn-lg disabled" role="button">Link</a>

Bootstrap禁用按钮,但它看起来像链接

<button type="button" class="btn btn-link">Link</button>

我使用:

.current-page a:hover {
    pointer-events: none !important;
}

这还不够;在某些浏览器中,它仍然会闪烁着显示链接。

我必须补充一句:

.current-page a {
    cursor: text !important;
}

在CSS中可以做到这一点:

.disabled { 光标:违约; pointer-events:没有; 文字修饰:没有; 颜色:黑色; } <a href="https://www.google.com" target="_blank" class="disabled">谷歌</a>

看:

请注意文字装饰:无;颜色:黑色;不是必需的,但它使链接看起来更像纯文本。

如果你想在表单上只使用HTML/CSS,另一种选择是使用按钮。设置它的样式并设置disabled属性。

如。 http://jsfiddle.net/cFTxH/1/