是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
当前回答
你可以将href属性设置为javascript:void(0):
.disabled { /*禁用链接样式*/ 颜色:黑色; } <a class="disabled" href="javascript:void(0)“链接> < / >
其他回答
从这个解决方案:
(aria-current =“页面”){ pointer-events:没有; 光标:违约; 文字修饰:没有; 颜色:黑色; } <a href=" Link .html" aria-current="page">Link</a> .html
有关浏览器支持,请参见https://caniuse.com/#feat=pointer-events。如果你需要支持ie浏览器,有一个变通办法;请看这个答案。
警告:在CSS中对非svg元素使用指针事件是实验性的。该特性曾经是css3 UI草案规范的一部分,但由于许多悬而未决的问题,已被推迟到css4。
<a href="#!">1)链接非定向url</a><br><br> <a href="#!" disabled >2) Link With With disable url</a><br><br>
Pointer-events:none将禁用该链接:
.disabled {
pointer-events: none;
}
<a href="#" class="disabled">link</a>
我在网上搜索了一下,没有比这更好的了。 基本上,要禁用按钮点击功能,只需使用jQuery添加CSS样式,如下所示:
$("#myLink").css({ 'pointer-events': 'none' });
然后再次启用它,这样做
$("#myLink").css({ 'pointer-events': '' });
在Firefox和Internet Explorer 11上进行了检查,可以正常工作。
你可以使用这个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>