XML technologies / CSS / CSS Cookbook / Printing / Inserting special characters before links
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
When printing a document, a special character such as » should be inserted before links.
Solution
As shown in the recipe Displaying the URI after a link, use the pseudo-element :after in the print stylesheet to insert the URI after the actual link:
p a:after {
content: attr(href) ;
}Here we extend this concept to display the special character before the URI:
p a:before {
text-decoration: underline;
content: " \00BB " attr(href);
}The link now appears in print as follows:
Discussion
Remember to prefix the hexadecimal value with a backslash (\). To prevent the browser from displaying the character as plain text, prefix it with a backslash (\). The correct value for » is “00BB”. Without the backslash, the result would look like this:
Because of CSS syntax, the property content cannot use HTML entities (here: » or »). Instead, use the hexadecimal value of the corresponding Unicode character, prefixed with a backslash.
Naturally, these special characters can be used for any media type, not just printing. Try this on your web page. To display the output in the browser as well, the media type must be all or screen.
Currently, content generated by pseudo-elements is supported only by Firefox, Netscape 6+, Safari and, to a limited extent, Opera. Unfortunately, this technique does not work in Internet Explorer.
See also
Further explanations of Special characters in CSS.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln