使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
例如,如果我有这个:
<a style="" href="page.html">page link</a>
有什么我可以使用的style属性,这将使得链接不可点击,不会带我到page.html。
或者我唯一的选择是不要在锚标签中包装“页面链接”?
编辑:我想说明为什么要这样做,以便人们能够提供更好的建议。 我正在设置我的应用程序,以便开发人员可以选择他们想要什么类型的导航样式。
所以我有一个链接列表,一个总是被选中,其他的都不是。 对于未选择的链接,我显然希望这些链接成为普通可点击的锚标签。 但是对于选定的链接,有些人更喜欢链接保持可点击,而其他人喜欢使其不可点击。
现在我可以轻松地以编程方式在所选链接周围不包含锚标签。 但是,如果我可以随时将选定的链接包装成如下所示,那么它会更加优雅:
<a id="current" href="link.html">link</a>
然后让开发者通过css控制链接风格。
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 remains clickable while others like to make it not clickable.
Now I could easily just programmatically not wrap an 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.
最满意答案
你可以使用这个css:
.inactiveLink { pointer-events: none; cursor: default; }
然后将类分配给您的html代码:
<a style="" href="page.html" class="inactiveLink">page link</a>
它使链接不可点击,光标样式是箭头,而不是链接所具有的手。
或在html中使用此样式:
<a style="pointer-events: none; cursor: default;" href="page.html">page link</a>
但我建议第一种方法。
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 an 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.
相关问答
更多-
CSS3中的按钮不可点击(Button in CSS3 not clickable)[2022-10-11]
添加相对于li元素的位置,然后拉伸锚点。 ul li { display: block; float: left; background-color: #099; margin-right: 10px; padding: 10px 0px; text-align: center; width: 40px; opacity: 0.2; transition: all 0.2s ease-in-out 0s; /* Add pos ... -
CSS帮助锚标记(CSS Help with Anchor Tag)[2022-06-30]
它是underline ,没有underlined 。 It's underline, not underlined. -
绝对定位的锚标签(没有文字)在IE中不可点击(absolute positioned anchor tag (with no text) not clickable in IE)[2022-07-12]
我以前有这个确切的问题,总是让我厌烦了。 我不知道为什么会这样,但是我总是创建一个1px x 1px的透明PNG(或GIF),并在你的背景声明中使用它: a { background: url("/path/to/image.png") 0 0 repeat; } 希望这可以帮助。 PS - 不要用此指定任何实际的背景颜色。 只需使用上面的例子,它应该工作。 除此之外,尝试并设置您的锚点标签以显示为块,也可能在其中插入一个不间断的空间(因为它们当前为空,并且可能会跳过IE) a { display: bl ... -
使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)[2023-03-21]
你可以使用这个css: .inactiveLink { pointer-events: none; cursor: default; } 然后将类分配给您的html代码: page link 它使链接不可点击,光标样式是箭头,而不是链接所具有的手。 或在html中使用此样式:当没有javascript和有效的代码点击时,整个div链接到另一个页面,这是可能的吗? 谚语答案:不 当您已经发表了另一个评论时,将div嵌入a标签内无效。 但是,没有什么可以阻止您使标签与div类似,除了不能在其中嵌套其他块标记。 如果它适合您的标记,请在您a标签上设置display:block ,然后将a设置a float / float。 如果你违反了你的问题的前提,你需要避免javascript,因为其他人指出我们可以使用onClick事件处理程序。 jQuery是一个流行的选择,使这个易于维护。 ...你需要调用setMovementMethod : aboutL1.setMovementMethod(LinkMovementMethod.getInstance()); (你可能甚至不需要调用Linkify.addLinks因为你使用Html.fromHtml ,但我不能完全记得)。 You need to call setMovementMethod: aboutL1.setMovementMethod(LinkMovementMethod.getInstance()); (you may not ...你不能用内联CSS做到这一点。 您必须使用普通的