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:50

You can set href attribute to javascript:void(0)

.disabled {
  /* Disabled link style */
  color: black;
}
<a class="disabled" href="javascript:void(0)">LINK</a>

查看更多
余欢
3楼-- · 2018-12-31 06:51

Demo here
Try this one

$('html').on('click', 'a.Link', function(event){
    event.preventDefault();
});
查看更多
高级女魔头
4楼-- · 2018-12-31 06:52

CSS can only be used to change the style of something. The best you could probably do with pure CSS is to hide the link altogether.

What you really need is some javascript. Here's how you'd do what you want using the jQuery library.

$('a.current-page').click(function() { return false; });
查看更多
不流泪的眼
5楼-- · 2018-12-31 06:52

If you want to stick to just HTML/CSS on a form, another option is to use a button. Style it and set the disabled attribute.

E.g. http://jsfiddle.net/cFTxH/1/

查看更多
看淡一切
6楼-- · 2018-12-31 06:52

The pointer-events property allows for control over how HTML elements respond to mouse/touch events – including CSS hover/active states, click/tap events in Javascript, and whether or not the cursor is visible.

That's not the only way you disable a Link, but a good CSS way which work in IE10+ and all new browsers:

.current-page {
  pointer-events: none;
  color: grey;
}
<a href="#" class="current-page">This link is disabled</a>

查看更多
浪荡孟婆
7楼-- · 2018-12-31 06:55

pointer-events:none will disable the link:

.disabled {
       pointer-events:none;
}
<a href="#" class="disabled">link</a>
查看更多
登录 后发表回答