链接中伪类文本修饰后的 CSS
我的问题的目标是创建一个在链接后添加文件类型的代码(以便人们知道他们是否应该期待任何特殊文件)。现在可以选择使用图像来执行此操作,但我不太喜欢它,并且我更喜欢将文件类型放在不同大小的方括号之间。我的方法是按以下方式使用 :after 伪类
a[href$='.doc']:after, a[href$='.rtf']:after {
content: " [DOC]";
font-family: Monospace;
font-size: 60%;
font-weight:bolder;
color:red;
position:relative;
top: -0.8em;
}
但是,这给我带来了一个非常奇怪的问题。内容似乎位于作为链接一部分的块中。因此,链接下划线在“[DOC]”下的链接之后继续。
所以问题非常简单:有没有办法以另一种方式执行此操作,或者确保我可以控制“[DOC]”下的内容与链接下的内容分开?
The goal of my question is to create a code which adds the filetype after a link (so that people know whether they should expect any special files). Now there are options to do this using an image, but I don't really like it and I would prefer to have the file type between square brackets in a different size. My approach is to use the :after pseudoclass in the following way
a[href$='.doc']:after, a[href$='.rtf']:after {
content: " [DOC]";
font-family: Monospace;
font-size: 60%;
font-weight:bolder;
color:red;
position:relative;
top: -0.8em;
}
However, this gets me a very strange problem. The content seems to be in a block which is part of the link. Therefore the link underlining continues after the link under the "[DOC]".
So the question is pretty straightforward: Is there a way to either do this in another way or to make sure that I can control what is under the "[DOC]" separately from what is under the link?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加 display: inline-block;
没有在 IE 中进行测试,但我认为 IE 在属性选择器和 :after 或两者上都有问题。
Try adding display: inline-block;
not tested in IE but I think IE has trouble with attribute selectors and :after or both.
我希望有人能指出一种更干净的方法,但这可行:
现场演示
HTML:
CSS:
I hope someone will swoop down and point out a cleaner way, but this works:
Live Demo
HTML:
CSS:
所有:我可能会坚持使用图像,因为这似乎更强大(就支持浏览器而言)。我天真的世界观,即纯文本应该总是比图像更容易,在这种情况下是错误的;)。
All: I will probably stick to an image since that seems to be a bit more robust (in terms of supporting browsers). My naive view of the world, that a plain text should always be easier than an image is wrong in this case ;).