[英]Have CSS hover style affect only hyperlinks
When I define styles for hyperlinks , the "hover" style affects parts where the <a>
tag is used only to define an ID, not a hyperlink, for example <a id="a1">TEXT</a>
. 当我定义超链接的样式时 ,“悬停”样式会影响
<a>
标签仅用于定义ID而不是超链接的部分,例如<a id="a1">TEXT</a>
。
How can I get a hover style only for <a>
tags that contain a hyperlink ? 如何仅对包含超链接的
<a>
标签获得悬停样式?
You can use an attribute selector… 您可以使用属性选择器…
a[href]:hover {
}
… or define hover states for linked and visited links: …或为链接和访问链接定义悬停状态:
a:link:hover,
a:visited:hover {
}
You could also not use a
elements for non-links . 你也可以不使用
a
非链接元素 。
Since the introduction of HTML 4 in the mid-1990s, any element can be a link target so long as it has an id. 自从1990年代中期引入HTML 4以来, 任何元素都可以成为链接目标,只要它具有ID。
<section id="a1">
<h2>TEXT</h2>
<p>More content</p>
</section>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.