css a:链接样式文本和图像

发布于 2024-09-24 06:15:15 字数 355 浏览 6 评论 0原文

我有一个快速的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枫以 2024-10-01 06:15:15

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:

a img {
    display: block;
    }

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.

逆夏时光 2024-10-01 06:15:15

怎么样

a[href$=jpg]:hover, 
a[href$=jpeg]:hover, 
a[href$=png]:hover, 
a[href$=gif]:hover {
        text-decoration: none;
        border: 0;
        border: none;
        }

How about

a[href$=jpg]:hover, 
a[href$=jpeg]:hover, 
a[href$=png]:hover, 
a[href$=gif]:hover {
        text-decoration: none;
        border: 0;
        border: none;
        }
滥情空心 2024-10-01 06:15:15

根据 css 特异性,只要您将图像边框 css 放在其他CSS。

顺便说一句,没有必要将 p 和 td 像这样分开。

#main a {
    color:#7b9a04;
    text-decoration:none;
}

#main a:hover {
    color:#333;
    border-bottom:solid 1px #7b9a04;
}

确实是您所需要的。

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.

#main a {
    color:#7b9a04;
    text-decoration:none;
}

#main a:hover {
    color:#333;
    border-bottom:solid 1px #7b9a04;
}

Is really all you need.

锦上情书 2024-10-01 06:15:15

在悬停声明之后显式定义图像无边框怎么样?

#main a:hover {
  border-bottom: solid 1px #7b9a04;
}

img {
  border: none;
}

what about explicitly defining images to have no border, after the hover declaration?

#main a:hover {
  border-bottom: solid 1px #7b9a04;
}

img {
  border: none;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文