附件的 CSS 样式 - 自动在文本之前添加图标
我想知道制作一个下载类,在文本前面放置一个图标,并且文本和图标都是附加文件链接的一部分,这有多难。有没有一种简单的方法可以用 CSS 来做到这一点?
I was wondering how hard it is to make a class for downloads that places an icon right before the text and both text and icon are part of the link to the attached file. Is there a simple way to do this with CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设所有下载链接都是类名“downloadLink”的
a
元素:如果这些链接的格式为:
那么 css:
将为带有
href< 的链接提供特定背景以
pdf
或png
结尾的 /code> 属性。这种方法基于 CSS3 的属性选择器,这可能会降低跨浏览器兼容性,但是根据 Quirksmode 的兼容性表 不是(基本上上面的所有内容,包括 IE7 都应该在 IE 或其他浏览器中支持此功能(尽管它没有指定支持哪些选择器))浏览器)。参考文献:
$=
选择器。Assuming that all links to downloads are
a
elements, of class-name 'downloadLink':If those links are of the format:
Then the css:
Will give specific backgrounds to links with a
href
attribute that ends withpdf
orpng
. This approach is based around CSS3's attribute-selectors, which might reduce cross-browser compatibility but, according to Quirksmode's compatibility table not by much (basically everything above, and including, IE7 should support this (albeit it doesn't specify which of the selectors are supported) in IE or other browsers).References:
$=
selector.