Code Snippet
Signify “PDF Bombs”
Any ol' anchor link can be a link to a PDF document, but clicking a link like that thinking otherwise can be surprising and uncomfortable for a user. This CSS can visually signify those links.
/* Add " (PDF)" text after links that go to PDFs */
a[href$=".pdf"]:after { content: " (PDF)"; }
/* If file size specified as data attribute, use that too */
a[href$=".pdf"][data-size]:after { content: " (PDF, " attr(data-size) ")"; }
So...
<p>Watch out for the <a href="some.pdf">PDF bomb</a> here!</p>
Becomes:
Watch out for the PDF bomb (PDF) here!
Or...
<p>Watch out for the <a href="some.pdf" data-size="2 MB">PDF bomb</a> here!</p>
Becomes:
Watch out for the PDF bomb (PDF, 2 MB) here!
Long ago I found this:
http://pooliestudios.com/projects/iconize/
It’s perhaps more useful than adding :after { content …}.
Another nice and useful example is the way Wikipedia links to external sites.
Cheers,
R
The issue with this that it has to make an HTTP request for one of those images. Unless you did some sort of magic with sprite images, I think appending (PDF) to the end of a PDF link will do just fine.
Also sites with those little icons seem to get a bit cluttered.
Roflo, great resource! thx
Anyway to do that with a sprite image?
can you style the Attribute
(PDF, 2 MB)
the 2 MB part. with css? like possibly give it a class?
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.