CSS Hover 属性位于子元素而不是整个元素上
如下所示,
希望这是有道理的 - 我的html
<a href="#" class="someclass">An <span class="sub">Interesting</span> Link</a>
其中 css 只是颜色信息。我想做的是,当您将鼠标悬停在整个链接上时,只有“子”信息受到悬停属性的影响。虽然这在 javascript 中很容易做到,但我很好奇 css 是否允许这种行为。如果我尝试写这个,它可能看起来像
a:hover{
.sub{color:newcolor};
}
,但我从未见过这样的东西,显然它不起作用
Hopefully this makes sense - my html is as follows
html
<a href="#" class="someclass">An <span class="sub">Interesting</span> Link</a>
where the css is simply color information. What I'd like to do is to make it so when you mouseover the link as a whole only the "sub" information is affected by the hover attribute. While this would be easy enough to do in javascript I was curious as to whether or not css allowed for this behavior. If I were to try to write this it would probably look like
a:hover{
.sub{color:newcolor};
}
however I've never seen anything like that and obviously it doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:
如果您只需要将其应用于该特定类:
Like this:
If you need to apply it only to that specific class: