Pseudo-elementsPseudo-elements provide the effect of extra markup elements magically appearing in your document, although you don't actually add any extra markup. Here are some examples. This pseudo-class x:first-letter <-- a p:firstletter {font-size:300%; float:left;}
enables you, for example, to create a large drop-cap effect at the start of a paragraph. This pseudo-class x:first-line <-- a
enables you to style the first line of (usually) a paragraph of text. For example, p:first-line{font-varient:small-caps;} results in the first line, not surprisingly, being in small capital letters. If you have a liquid layout where the line length changes as the browser window is sized, words automatically change format as required so that only the first line is styled in this way.
These two pseudo-classes x:before and x:after cause specified text to be added in before and after an element, so this markup <h1 class="age">25</h1> and these styles h1.age:before {content:"Age: "} h1.age:after {content:" years old."}
result in text that reads "Age: 25 years old." Note that the spaces added inside the quoted content strings ensure proper spacing in the resultant output. These two selectors are especially useful when the tag's content is being generated as a result of a database query; if all the result contains is the number, then these selectors allow you to provide that data point with some meaningful context when you display it for the user. |