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:

Printed link appearance

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:

Incorrect link appearance

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.

  

 

 

 

back to top