是否可以使用CSS无法点击/链接HTML锚定代码? [英] Is it possible to make an HTML anchor tag not clickable/linkable using CSS?

查看:198
本文介绍了是否可以使用CSS无法点击/链接HTML锚定代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有这个:



< a style =href =page.html> page link< / a>



有什么我可以用于样式属性,这将使链接不可点击,


$ b

编辑:我想说明为什么我想这样做,以便人们可以提供更好的建议。我尝试设置我的应用程序,以便开发人员可以选择他们想要的导航样式。



所以我有一个链接列表,和所有其他人不是。对于未选择的链接,我显然希望这些是正常的可点击锚标签。但对于所选链接,有些人更喜欢链接保持可点击,而其他人则喜欢使其不可点击。



现在我可以轻松地只是通过编程方式链接。但我认为,如果我可以总是包装选择的链接在像下面这样会更加优雅:



< a id =currenthref =link.html> link< / a>



,然后让开发人员通过css控制链接样式。 >

解决方案

您可以使用此css:

  .inactiveLink {
pointer-events:none;
cursor:default;
}

然后将类分配给您的html代码:

 < a style =href =page.htmlclass =inactiveLink>页链接< / a> 

它使链接不可点击,光标样式为箭头,而不是手的链接

  



a style =pointer-events:none; cursor:default; href =page.html>页链接< / a>

但我建议第一种方法。


For example if I have this:

<a style="" href="page.html">page link</a>

is there anything I can use for the style attribute that will make it so the link isn't clickable and won't take me to page.html.

Or is my only option to simply not wrap 'page link' in an anchor tag?

Edit: I want to state why I want to do this so that people may be able to provide better advice. I am trying to set up my application so that the developer can choose what type of navigation style they want.

So I have a list of links and one is always currently selected and all the others aren't. For the links that are not selected I obviously want those to be normal clickable anchor tags. But for the selected link some people prefer that the link remain clickable while others like to make it not clickable.

Now I could easily just programmatically not wrap anchor tags around the selected link. But I figure it will be more elegant if I can always wrap the selected link in something like:

<a id="current" href="link.html">link</a>

and then let the developer control the linking style through css.

解决方案

You can use this css:

.inactiveLink {
   pointer-events: none;
   cursor: default;
}

And then assign the class to your html code:

<a style="" href="page.html" class="inactiveLink">page link</a>

It makes the link not clickeable and the cursor style as a arrow, not a hand as the links have.

or use this style in the html:

<a style="pointer-events: none; cursor: default;" href="page.html">page link</a>

but I suggest the first approach.

这篇关于是否可以使用CSS无法点击/链接HTML锚定代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆