如何修复文本式悬停效果的不均匀应用(仅桌面用户 - 网站尚未移动响应式)?
我正在尝试仅使用CSS为我的链接创建滑动下划线悬停效果。效果有效,因此它大多是成功的,但是我想修复的下划线的厚度不平衡,但我不确定如何。
我找到了一种资源,该资源指示我使用背景图像线性梯度设置,以便如果线跨越多行,则效果仍然有效。该资源在这里:
https://nerdcowboy.com/blog/blog/sliding-underined-lindin-links/-links/-links/
我正在使用第三个效果,它将下划线滑入和向外滑动。
该网站尚未移动响应,因此它只会出现在最大化的桌面窗口中。您可以浏览该页面并悬停在链接上,以了解我的意思。请记住,该网站仍然是一个正在进行的工作。这是网页:
https://sciencexfantasy.com/the-fundamentals.com/the-fundamentals-of - 写作/
这是我用于效果的CSS代码:
article a, .widget a {
color: #a90000;
font-weight: bold;
background-image: linear-gradient(#000000, #000000);
background-size: 0% .1em;
background-position-y: 100%;
background-position-x: 100%;
background-repeat: no-repeat;
transition: background-size 0.2s ease-in-out;
}
article a:hover, .widget a:hover, article a:focus, article a:active, .widget a:focus, .widget a:active {
background-size: 100% 0.1em;
background-position-x: 0%;
}
使用0.1EM建议的背景高度建议的资源,以便如果文本大小更改,则可以调整。例如,我尝试使用2PX来纠正此问题,但即使在页面中的整个链接中也适用于不均匀。
有人对此有修复吗?
I'm trying to create a sliding underline hover effect for my links using css only. The effect works so it's mostly successful but there's been an uneven application of the thickness of the underline that I want to fix but I'm not sure how.
I found a resource that instructed me to use the background-image linear gradient setting so that if the line spans multiple lines, the effect still works. That resource is here:
https://nerdcowboy.com/blog/sliding-underlined-links/
I'm using the third effect, which slides the underline in and out.
The site is not mobile-responsive yet so it will only appear right in a maximized desktop window. You can go through the page and hover over the links to see what I mean. Bear in mind, the site is still a work-in-progress. This is the web page:
https://sciencexfantasy.com/the-fundamentals-of-fiction-writing/
This is the css code I used for the effect:
article a, .widget a {
color: #a90000;
font-weight: bold;
background-image: linear-gradient(#000000, #000000);
background-size: 0% .1em;
background-position-y: 100%;
background-position-x: 100%;
background-repeat: no-repeat;
transition: background-size 0.2s ease-in-out;
}
article a:hover, .widget a:hover, article a:focus, article a:active, .widget a:focus, .widget a:active {
background-size: 100% 0.1em;
background-position-x: 0%;
}
The resource suggested using 0.1em for the background height so that if the text size changes, it'll adjust. I've tried to correct this by using 2px, for example, but even that applies unevenly throughout the links in the page.
Does anyone have a fix for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要更改背景大小,则需要在悬停和元素本身中更改。
这样:
很可能是因为字体大小。您的大多数文本高度是
17.6px
,只有回到顶部
链接是16.6px
。那就是我可以看到差异的地方。这也是我为元素和悬停添加线高的原因。如果以上代码不起作用,请尝试以下操作:2.5px
更改为0.2CH
14.5px 到
1.8
从我测试的内容中,

正常工作。
If you will change the background-size, you need to change both in hover and the element itself.
Like this:
It is most probably because of the font size. Most of your text height is
17.6px
and only theBack to Top
link is16.6px
. That's where I can see the difference. That is also the reason why I added a line height for both the element and the hover. If the above code does not work, try these:2.5px
to0.2ch
14.5px
to1.8
From what I have tested,

It works okay.