是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
是否有一种方法禁用链接使用CSS?
我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。
当前回答
简单地使用你的标签没有链接,不包括任何链接属性。
其他回答
.disabled { pointer-events:没有; 光标:违约; 透明度:0.6; } <a href="#" class="disabled">link</a>
您还可以调整另一个元素的大小,使其覆盖链接(使用正确的z-index):这将“吃掉”点击。
(我们偶然发现这一点,因为我们有一个问题,突然不活跃的链接,由于“响应式”设计导致H2覆盖他们时,浏览器窗口的移动大小。)
<a href="#!">1)链接非定向url</a><br><br> <a href="#!" disabled >2) Link With With disable url</a><br><br>
你可以使用这个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>
你也可以试试这个
<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>