如何仅删除 a:before 中的下划线?
我有一组使用 :before
来应用箭头的样式链接。
它在所有浏览器中看起来都不错,但是当我将下划线应用于链接时,我不想在 :before
部分(箭头)上有下划线。
请参阅 jsfiddle 例如: http://jsfiddle.net/r42e5/1/
是否可以删除这?我使用 #test pa:hover:before
进行的测试样式确实得到了应用(根据 Firebug),但下划线仍然存在。
有什么办法可以避免这种情况吗?
#test {
color: #B2B2B2;
}
#test p a {
color: #B2B2B2;
text-decoration: none;
}
#test p a:hover {
text-decoration: underline;
}
#test p a:before {
color: #B2B2B2;
content: "► ";
text-decoration: none;
}
#test p a:hover:before {
text-decoration: none;
}
<div id="test">
<p><a href="#">A link</a></p>
<p><a href="#">Another link</a></p>
</div>
I have a set of styled links using the :before
to apply an arrow.
It looks good in all browser, but when I apply the underline to the link, I don't want to have underline on the :before
part (the arrow).
See jsfiddle for example: http://jsfiddle.net/r42e5/1/
Is it possible to remove this? The test-style I sat with #test p a:hover:before
does get applied (according to Firebug), but the underline is still there.
Any way to avoid this?
#test {
color: #B2B2B2;
}
#test p a {
color: #B2B2B2;
text-decoration: none;
}
#test p a:hover {
text-decoration: underline;
}
#test p a:before {
color: #B2B2B2;
content: "► ";
text-decoration: none;
}
#test p a:hover:before {
text-decoration: none;
}
<div id="test">
<p><a href="#">A link</a></p>
<p><a href="#">Another link</a></p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的,如果将内联元素的显示样式从
display:inline
(默认)更改为display:inline-block
:这是因为 CSS 规范说:
(强调我的。)
演示:http://jsfiddle.net/r42e5/10/
感谢@Oriol 提供了解决方法,促使我检查规范并查看该解决方法是否合法。
Yes, if you change the display style of the inline element from
display:inline
(the default) todisplay:inline-block
:This is because the CSS specs say:
(Emphasis mine.)
Demo: http://jsfiddle.net/r42e5/10/
Thanks to @Oriol for providing the workaround that prompted me to check the specs and see that the workaround is legal.
IE8-11 中存在一个错误,因此单独使用
display:inline-block;
在那里不起作用。我找到了解决此错误的方法,方法是为 :before-content 显式设置
text-decoration:underline;
,然后使用text-decoration:none;
再次覆盖此规则。代码>这里的工作示例:
http://jsfiddle.net/95C2M/
更新:
由于 jsfiddle 不再支持 IE8,只需将这个简单的演示代码粘贴到本地 html 文件中并在 IE8 中打开它:
There is a Bug in IE8-11, so using
display:inline-block;
alone won't work there.I've found a solution for this bug, by explicitly setting
text-decoration:underline;
for the :before-content and then overwrite this rule again withtext-decoration:none;
Working example here:
http://jsfiddle.net/95C2M/
Update:
Since jsfiddle does not work with IE8 anymore, just paste this simple demo-code in a local html file and open it in IE8:
您可以将以下内容添加到
:before
元素中:使用
display: inline-block
下划线消失。但问题是三角形之后的空间折叠并没有显示出来。要修复此问题,您可以使用white-space: pre-wrap
或white-space: pre
。演示:http://jsfiddle.net/r42e5/9/
You can do it adding the following to the
:before
element:With
display: inline-block
the underline disappears. But then the problem is that the space after the triangle collapses and is not shown. To fix it, you can usewhite-space: pre-wrap
orwhite-space: pre
.Demo: http://jsfiddle.net/r42e5/9/
将您的链接包装在跨度中,并将文本装饰添加到 a:hover 上的跨度中,如下所示,
我已将您的小提琴更新为我认为您正在尝试执行的操作。 http://jsfiddle.net/r42e5/4/
Wrap your links in spans and add the text-decoration to the span on the a:hover like this,
I have updated your fiddle to what I think you are trying to do. http://jsfiddle.net/r42e5/4/
尝试使用:
这样可以吗?
try using instead:
will that do?
用这个
use this