“文字装饰”和“:after”伪元素,在 Firefox 8 中

发布于 2024-12-16 18:25:32 字数 1323 浏览 2 评论 0原文

在一个页面(我自己维护,因此可以将浏览器支持限制为 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 添加到链接本身

http://cssdesk.com/5TqEN

最终注意:我想要它至少可以在 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

…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

http://cssdesk.com/5TqEN

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 技术交流群。

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

发布评论

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

评论(1

初见终念 2024-12-23 18:25:32

我想出了这个 http://jsfiddle.net/wGb68/4/

a[href^='http://stackoverflow.com/'] {
    padding-right: 15px;
    display: inline-block; /* not needed, but fixes Chrome and Opera */
}

a[href^='http://stackoverflow.com/']:after {
    font-size: x-small;
    padding-left: 1px;
    content: "SO";
    color: #333;

    position: absolute;
}

清理得很差text-decoration 仅适用于使用此代码的 Firefox 和 Opera。我无法让它在任何其他浏览器中工作。 :/

Firefox 中不需要 display: inline-block ,但在 Opera 和 Chrome 中没有它,“SO”不会跟随换行符,甚至会与容器重叠。

I came with up with this http://jsfiddle.net/wGb68/4/

a[href^='http://stackoverflow.com/'] {
    padding-right: 15px;
    display: inline-block; /* not needed, but fixes Chrome and Opera */
}

a[href^='http://stackoverflow.com/']:after {
    font-size: x-small;
    padding-left: 1px;
    content: "SO";
    color: #333;

    position: absolute;
}

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.

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