“文字装饰”和“:after”伪元素,在 Firefox 8 中
在一个页面(我自己维护,因此可以将浏览器支持限制为 FF 3.5+)上,我想在每个 StackOverflow.com 链接后添加“SO”。首先我是这样做的……
a[href^='https://stackoverflow.com/']:after {
content: "SO";
font-size: x-small;
color: #333333;
padding-left: 1px;
position: relative;
bottom: 3px;
}
但是 Firefox 像链接本身一样强调了“SO”。阅读问题后
...我得到了以下解决方案:
a[href^='https://stackoverflow.com/']:after {
content: "SO";
font-size: x-small;
color: #333333;
padding-left: 1px;
position: relative;
bottom: 3px;
/* clear the underline */
padding-bottom: 5px;
background-color: white;
}
也许它是 hack'ish,但它相当直观(下划线被上面的背景隐藏了)并且效果很好(我不记得我在 FF 3.5 和 FF 7 以外的浏览器中检查过它,但 FF 仍然是我真正想要支持的唯一浏览器)。问题是代码在 FF 8 中损坏:上面的下划线清除代码不起作用。所以我正在寻找解决方案。
实际上,我已经找到了一个:添加“display:inline-block”,但是:
- 它可能导致“SO”被包装到新行,
- 它不能与旧的下划线清除代码一起使用,因为
padding-bottom
添加到链接本身
最终注意:我想要它至少可以在 FF 3.5 和 FF 8 中工作,仅使用 CSS,无需将“SO”文本制作为图像,比 inline-block
解决方案更好
On a page (which I maintain for myself and thus can restrict browser support to FF 3.5+) I'd like to add "SO" after each link to StackOverflow.com. First I did it like this…
a[href^='https://stackoverflow.com/']:after {
content: "SO";
font-size: x-small;
color: #333333;
padding-left: 1px;
position: relative;
bottom: 3px;
}
…but Firefox underlined "SO" like the link itself. After reading questions
- “text-decoration” and the “:after” pseudo-element, revisited
- “text-decoration” and the “:after” pseudo-element
…I got to the following solution:
a[href^='https://stackoverflow.com/']:after {
content: "SO";
font-size: x-small;
color: #333333;
padding-left: 1px;
position: relative;
bottom: 3px;
/* clear the underline */
padding-bottom: 5px;
background-color: white;
}
Maybe it's hack'ish, but it's rather intuitive (the underline is hidden by the background above it) and it worked nice (I don't remember I checked it in browsers other than FF 3.5 and FF 7, but still FF is the only browser I really want to support). The problem is that the code broke in FF 8: the underline-clearing code above does not work. So I'm looking for a solution.
Actually, I already find one: adding "display: inline-block", but:
- it can cause "SO" to be wrapped to a new line
- it can't be used together with the old underline-clearing code, because that
padding-bottom
is added to the link itself
Final note: I want it to work at least in FF 3.5 and FF 8, with only CSS, without making "SO" text an image, better than the inline-block
solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了这个 http://jsfiddle.net/wGb68/4/
清理得很差
text-decoration
仅适用于使用此代码的 Firefox 和 Opera。我无法让它在任何其他浏览器中工作。 :/Firefox 中不需要
display: inline-block
,但在 Opera 和 Chrome 中没有它,“SO”不会跟随换行符,甚至会与容器重叠。I came with up with this http://jsfiddle.net/wGb68/4/
Poorly the clearing of the
text-decoration
only works in Firefox and Opera with this code. I could not bring it to work in any other browser. :/The
display: inline-block
is not needed in Firefox, but without it in Opera and Chrome the "SO" don't follows a linebreak, and even overlaps the container.