(originally posted April 2, 2007. Updated to appear at front for a current project)
Character References in CSS Generated Content Strings
With web standards compliancy in mind, a desire to program using valid markup, to use the right DTD, etc., there inevitably comes difficulty, and unexpected challenges.
Many times when i’ve used an NCR, a named entity, or maybe even an ASCII control-character, i have had some sort of problem in achieving my desired output. Such problems are common in situations where i’ve used CSS Generated content.
I welcome feedback on this issue– i would love to hear the recommendations of others who’ve suffered this problems, and who have found their own solutions.
Unicode Character Encoding Syntax: the Solution?
In my experience, the compatibility of the various languages character encoding syntax with that of CSS 2.1 is unpredictable– at least to the point at which one understands the CSS specification itself. What may work in PHP, XHTML, and other languages for generating a Newline Character
may not work in CSS. The developer’s best chance of success here is to gain a thorough understanding of the recommended syntax for character encodings to use in CSS Generated Content.
The first thing the developer must realize is that, in order to insert characters– especially <CONTROL>
characters, such as the NEWLINE
control character, the CSS content
property is required. Content
is a CSS property which allows the developer to insert characters (automatically generated, or user-defined) into the document output.
Here I offer an account of my own success with outputting Encoded characters through a CSS content
String by way of the CSS :before pseudo-element.
CSS Content :before and :after
NOTE: If you wish to use the CSS content property to include a new line, that is– to generate a new line within the string output for aesthetic value, I recommend reading the section titled Characters and Case (Section 4.1.3) of the W3C CSS 2.1 Recommendation or CSS 2 Specification, specifically that section which describes the use of the backslash, and escaped characters. Direct your attention to the bullet-point section which begins, “ In CSS 2.1, a backslash () character indicates three types of character escapes. ”, and moreover, includes the following important rule:
If a character in the range [0-9a-f] follows the hexadecimal number, the end of the number needs to be made clear. There are two ways to do that:
1. with a space (or other whitespace character): “26 B” (“&B”). In this case, user agents should treat a “CR/LF” pair (U+000D/U+000A) as a single whitespace character.
2. by providing exactly 6 hexadecimal digits: “