Let your readers know before they click a link and it opens up some large application like Acrobat, Word, Excel, or Quicktime.

The HTML for the above link has no styles attached to it:
<a href="news/issue12.pdf">View Latest Issue</a>
The trick is all in the CSS:
a[href $='.pdf'] {
padding-right: 18px;
background: transparent url(icon_pdf.gif) no-repeat center right;
}
Now when you link to a PDF, your reader will be prepared. Other ideas for this include Word and Excel docs, and even mailto: links (for which you need to use the ^= option instead of $= to search the beginning of string). Looking at the first line of the code, you can see this can be used on any element and any of its attributes.

16 Comments
This is a fantastic tip!
We do a lot of websites for trade associations and this tip would definitely save us and our clients time. Thanks Kevin!
That’s awesome!
Definitely adding CSS For Lunch to my Google Reader.
Pretty sure that won’t work in a couple of browsers
but nice quick little add on, thanks for the tip!
I think i would use jquery (since i always use it, might as well use its functionality) to do the same selection but add a generic class to each element matched. maybe .pdflink and add the css to that. This way it will load in ie6 and such.
Wow, great tip! I think I’m going to do something that’s in a bit of reverse, and add an “external link” icon to appropriate content. So if we can use ^= to search the beginning, I can set links of a certain class to have the external link icon, UNLESS it starts with my domain. Very cool!
Search “iconize”. Someone already did the legwork.
PDF files support data after the .pdf similar to how URLs do with query strings. These can direct your to a specific page. I suspect that the [href $=’.pdf’] should be a bit more complex for this to work in all cases
I love this.
Very Very Helpful.
Interesting! Please contact us for further marketing. Kind regards / Oakleaf Marketing http://www.oakleafnow.com
very usefull!
Wow, that’s a great effect, I’m going to use that.
Very useful, clever….
Wow, what a simple an elegant solution, I’ll defintately be using this on my sites from now on, Thanks!
I stumbled this article on accident and im sure glad i did, GREAT TIP! I have been looking for something like this for a while now. Thank you, keep it up!
Great tricks, hope people stop using ie6 so we can use this
Very nice, no more manually linking those!
This is how Wikipedia adds its link images. You can make the icons only appear next to external links and not JavaScript links, as I’ve done here… http://discussionator.com/unify.html
11 Trackbacks
[…] CSS for Lunch Posted by Tiago Filed in Geek, […]
[…] Read more […]
[…] CSS for lunch ยป Attach Icons to Links Automatically (tags: webdev webdesign web tips css) […]
Vicodin side effects….
Cheap vicodin. Vicodin side effects. Vicodin no prescription. Buying cod vicodin. Buy vicodin online without. Buy vicodin. Vicodin withdrawal. Vicodin withdrawal symtoms….
Long term vicodin use….
Signs of vicodin addictio. Vicodin. Buy vicodin without a prescription. How l ong does vicodin stay in your system….
Cheap percocet….
Percocet without prescription cheap cod. Percocet without a prescription cheap. Cheap percocet….
Percocet high blood pressure….
Compare brand name and generic percocet. Percocet….
[…] Attach Icons to Links Automatically Let your readers know before they click a link and it opens up some large application like Acrobat, Word, Excel, or Quicktime. […]
Nymphet tgp….
Nymphet panites. Nymphet. Bbs and nymphet. Youngest nymphet sites. Nymphet russian….
Buy percocet online….
Buy percocet online. Buy percocet online no prescription. Buy percocet online without office visit….
vtafljxy…
vtafljxy…