How to disable a link using only CSS?

2018-12-31 06:26发布

Is there any way to disable a link using CSS?

I have a class called current-page and want links with this class to be disabled so that no action occurs when they are clicked.

标签: html css
20条回答
有味是清欢
2楼-- · 2018-12-31 06:56

Try this:

<style>
.btn-disable {
    display:inline-block;
    pointer-events: none;       
}
</style>
查看更多
长期被迫恋爱
3楼-- · 2018-12-31 06:57

CSS can't do that. CSS is for presentation only. Your options are:

  • Don't include the href attribute in your <a> tags.
  • Use JavaScript, to find the anchor elements with that class, and remove their href or onclick attributes accordingly. jQuery would help you with that (NickF showed how to do something similar but better).
查看更多
登录 后发表回答