css a:链接样式文本和图像
我有一个快速的 CSS 问题困扰着我,但我现在似乎无法弄清楚。
我已将页面上的链接设计为在悬停时具有底部边框,但底部边框也出现在具有链接的图像上,并且我不知道如何防止边框出现在图像上。
这是我目前拥有的。
#main a:hover {
border-bottom:solid 1px #7b9a04;
color:#333;
}
img, img a:hover {
border-bottom:none;
}
然而这似乎不起作用。我不认为任何其他样式会覆盖它,因为如果我删除 #main a:hover 样式,图像将不再具有底部边框,但网站上的其他链接也不会这样做。
I've got a quick css questions that's bugging me, and I can't seem to figure out right now.
I've styled the links on my page to have a bottom border on on hover, but it the bottom border is appearing on image that have links as well and I can't figure out how to keep the border from appearing on the images.
Here is what I currently have.
#main a:hover {
border-bottom:solid 1px #7b9a04;
color:#333;
}
img, img a:hover {
border-bottom:none;
}
However this doesn't seem to work. I don't think its any other style overriding it, because if I remove the #main a:hover style the images no longer have the bottom border, but none of the other links on the site do either then.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题出在链接元素
上,而不是图像链接本身。当您为
的悬停状态指定底部边框时,它也适用于包含图像的链接。因此,当您将鼠标悬停在此类链接(包含图像)上时,该链接将显示边框底部。不是图像。
不过这个问题有一个解决办法。尝试应用:
这将重置
样式。此方法有一个警告 - 将其与内联图像一起使用可能会破坏布局。所以要谨慎使用。
The problem is with the link element
<a>
, not with the image link itself. When you specify a bottom border for the hover state of<a>
, it also applies to the link that contains the image. So when you hover on such a link (containing an image), it's the link that shows the border-bottom. Not the image.There's a fix for this though. Try applying:
This will reset the
<a>
styling. There is one caveat for this method — using this with inline images might break the layout. So use it sparingly.怎么样
How about
根据 css 特异性,只要您将图像边框 css 放在其他CSS。
顺便说一句,没有必要将 p 和 td 像这样分开。
确实是您所需要的。
According to css specificity it should be working as long as youre putting the image border css after the other css.
As an aside there's no need to have p and td separated like that.
Is really all you need.
在悬停声明之后显式定义图像无边框怎么样?
what about explicitly defining images to have no border, after the hover declaration?