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

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


当前回答

身体{ font-family: 'Roboto', sans-serif; 粗细:500; } a.disable { pointer-events:没有; 颜色:黑色; 文字修饰:没有; } 正常< a href = " https://example.com " > < / > <a href="https://example.com" class="disable"> disable </a> .

其他回答

CSS做不到这一点。CSS仅用于表示。你的选择是:

不要在<a>标签中包含href属性。 使用JavaScript找到该类的锚元素,并相应地删除它们的href或onclick属性。jQuery将帮助您实现这一点(NickF展示了如何做类似的事情,但更好)。

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

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

你可以使用这个CSS内容:

a.button,button { display: inline-block; padding: 6px 15px; margin: 5px; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-image: none; border: 1px solid rgba(0, 0, 0, 0); border-radius: 4px; -moz-box-shadow: inset 0 3px 20px 0 #cdcdcd; -webkit-box-shadow: inset 0 3px 20px 0 #cdcdcd; box-shadow: inset 0 3px 20px 0 #cdcdcd; } a[disabled].button,button[disabled] { cursor: not-allowed; opacity: 0.4; pointer-events: none; -webkit-touch-callout: none; } a.button:active:not([disabled]),button:active:not([disabled]) { background-color: transparent !important; color: #2a2a2a !important; outline: 0; -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, .5); box-shadow: inset 0 3px 5px rgba(0, 0, 0, .5); } <button disabled="disabled">disabled!</button> <button>click me!</button> <a href="http://royansoft.com" disabled="disabled" class="button">test</a> <a href="http://royansoft.com" class="button">test2</a>

在CSS中可以做到这一点:

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

看:

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

演示 试试这个

$('html').on('click', 'a.Link', function(event){
    event.preventDefault();
});