CSS 链接图像带有下划线(“a”显示被设置为阻止)

发布于 2024-09-25 11:21:02 字数 649 浏览 7 评论 0原文

我有一个菜单,我希望每个单独的项目中文本周围的所有空间都能将用户带到指定的页面。我在网上环顾四周,发现最好的解决方案是将“a”显示设置为阻止,如下所示:

a {
    display: block;
    height: 100%;
    text-decoration: underline;
}

我已经设法使其完美工作,但想在其中一些图像中放入图像 - 例如日历图标事件选项。我注意到它现在也强调了链接。有什么办法可以摆脱这个吗?如果这有助于缩小原因/解决方案的范围,则链接的 padding-right 设置为 5px。

所以所有相关代码如下:

a {
    display: block;
    height: 100%;
    text-decoration: underline;
}
a > img {
    text-decoration: none;
    border: none;
    padding-right: 5px;
    width: 1.8em;
    height: 1.8em;
}

提前非常感谢。

此致,

理查德

PS 我在 Google Chrome 中遇到了这个问题 - 我目前尚未在任何其他浏览器中检查过它。

I have a menu for which I wanted all of the space around the text, within each individual item, to take the user to the specified page. I looked around on the web and found that the best solution is to set the "a" display to block, as follows:

a {
    display: block;
    height: 100%;
    text-decoration: underline;
}

I have managed to get this working perfectly but want to put images in some of them - like a calendar icon for the events option. I notice it is now underlining the links too. Is there any way to get rid of this? The links have padding-right set to 5px if that helps narrow down the cause / solution.

So all the relevant code is as follows:

a {
    display: block;
    height: 100%;
    text-decoration: underline;
}
a > img {
    text-decoration: none;
    border: none;
    padding-right: 5px;
    width: 1.8em;
    height: 1.8em;
}

Many thanks in advance.

Regards,

Richard

PS It is Google Chrome in which I am having this problem - I have not currently checked it in any other browsers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

那一片橙海, 2024-10-02 11:21:02

图像是内联元素,因此它们被视为文本的一部分。带下划线的不是图像,而是包含下划线的图像的文本,因此它无助于防止图像带下划线。

您可以通过浮动图像将图像变成块元素,然后它们就不是文本的一部分:

a > img {
    float: left;
    border: none;
    padding-right: 5px;
    width: 1.8em;
    height: 1.8em;
}

Images are inline elements, so they are treated as part of the text. It's not the image that is underlined, it's the text that contains the image that is underlined, so it doesn't help to prevent underlining for the image.

You can turn the images into block elements by floating them, then they are not part of the text:

a > img {
    float: left;
    border: none;
    padding-right: 5px;
    width: 1.8em;
    height: 1.8em;
}
一曲琵琶半遮面シ 2024-10-02 11:21:02

我认为最好的选择是摆脱 a 元素的下划线文本装饰属性,将链接文本放在具有公共类的 span 中,然后应用 text-decoration: underline 到该类。

I think your best option is to get rid of the underline text-decoration property for the a element, put the link text in a span with common class, and apply text-decoration: underline to that class.

所有深爱都是秘密 2024-10-02 11:21:02

我也带着同样的疑问奔跑着。将 text-decoration 设置为 none 对我来说很有效:

<a href="..." style="text-decoration:none;">
    <img src="...">
</a>

正如之前所说,您可以使用一个类来使其更加通用。

顺便说一句,很好的问题,当我在图像底部看到一些减号时,在我的网站上看起来很奇怪。然后我意识到这是一个底层。

I was running in the same doubt. The text-decoration set to none works for me:

<a href="..." style="text-decoration:none;">
    <img src="...">
</a>

As was said befor, you can use a class to make this more generic.

Nice question by the way, It looks totally strange in my website when I saw some minus at the bottom of images. Then I realize that was an underlying.

嘿哥们儿 2024-10-02 11:21:02

我尝试了评论中的所有方法都无济于事,对我有用的是修改包含所有标签的 div 。我有一种暗示,它们只有在处于绝对默认位置时才会带有下划线。这是每个标签包裹的 div,没有应用其他技巧。

.myDiv {
    display: flex; 
    justify-content: center;
    align-items: center;
}   

I tried eveything in the comments to no avail, what worked for me was modifying div which contained all the tags. I have an inkling that they are only underlined when in their absolute default position. Here was the div each tag was wrapped in, no other tricks were applied.

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