是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
当前回答
<a href="#!">1)链接非定向url</a><br><br> <a href="#!" disabled >2) Link With With disable url</a><br><br>
其他回答
CSS只能用来改变一些东西的样式。使用纯CSS所能做的最好的事情就是完全隐藏链接。
您真正需要的是一些JavaScript代码。下面是如何使用jQuery库完成您想做的事情。
$('a.current-page').click(function() { return false; });
你可以用CSS来做这件事的一种方法是在包装div上设置一个CSS,你设置它消失,其他东西会取代它的位置。
例如:
<div class="disabled">
<a class="toggleLink" href="wherever">blah</a>
<span class="toggleLink">blah</span
</div>
使用CSS
.disabled a.toggleLink { display: none; }
span.toggleLink { display: none; }
.disabled span.toggleLink { display: inline; }
要真正关闭a,您必须替换它的click事件或href,如其他人所述。
PS:澄清一下,我认为这是一个相当不整洁的解决方案,对于SEO来说也不是最好的,但我相信它是纯CSS最好的。
指针事件属性允许控制HTML元素如何 响应鼠标/触摸事件-包括CSS悬停/活动状态, 在JavaScript中点击/点击事件,以及光标是否在 可见。
这不是禁用链接的唯一方法,但这是一个很好的CSS方法,适用于Internet Explorer 10(及更高版本)和所有新浏览器:
.current-page { pointer-events:没有; 颜色:灰色; } <a href="#" class="current-page">该链接被禁用</a> .
.disabled { pointer-events:没有; 光标:违约; 透明度:0.6; } <a href="#" class="disabled">link</a>
你可以使用这个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>