XML technologies / CSS / Advanced websites with CSS / CSS property reference / content
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
Sometimes special content before or after an HTML element is useful. This “generated content” belongs to the design rather than the HTML document and comes from stylesheet instructions. The property content defines it and is used only with the pseudo-elements :before or :after.
Inherited: no
See also: counter-increment, counter-reset, quotes
Values
CSS2 allows many generated-content formats, several unsupported by current browsers (see “Compatibility”). Any combination below is valid; separate values with spaces in a declaration.
"arbitrary string": Produces arbitrary text before or after the element’s content. HTML tags cannot format the string: the browser would display them literally. Use CSS instead. The sequence “\A” inserts a line break within the string.url(http://www.url.de): Displays an external resource before or after the content, including images or entire pages inside HTML elements. No browser currently supports it.counter(name),counter(name, style),counters(name, string),counters(name, string, style): These formats automatically number elements. The CSS propertycounter-incrementincreases a variable by a specified amount;counter-resetresets it to zero or another number. The formatcounter(name)displays the counter in decimal. The formatcounter(name, style)also specifies a display style, using the same values aslist-style-type. The formatscounters(name, string)andcounters(name, string, style)define hierarchical multilevel numbering, such as “Section 5.2.3.” The argumentstringdefines the separator string, usually a period.attr(attribute): Displays an HTML attribute’s value, such astitlein a tag<a>, before or after the content.open-quote,close-quote: These formats insert quotation marks before or after an element’s content. The propertyquotesdefines their style.no-open-quote,no-close-quote: These formats create invisible “dummy” quotation marks used in the document’s logical syntax.
Default value: "" (empty string)
Compatibility
CSS version: 2
Netscape 6, Mozilla and Opera support only some formats, especially "arbitrary string" and quotation-mark formats. Internet Explorer for Windows through version 6 does not support this property.
Examples
This rule prefixes each paragraph of class note with “Anmerkung:”:
p.anmerkung:before {
content: "Anmerkung: ";
}
These rules surround every element span of class htmltag with angle quotation marks:
span.htmltag {
quotes: "<" ">";
}
span.htmltag:before {
content: open-quote;
}
span.htmltag:after {
content: close-quote;
} These rules surround every element blockquote with quotation marks. The third rule applies only to elements blockquote using the attribute cite. There, content automatically places the quotation source on the next line. Current browsers do not support this rule because it includes the format attr(attribute):
blockquote:before {
content: open-quote;
}
blockquote:after {
content: close-quote;
}
blockquote[cite]:after {
content: close-quote "\Aaus " attr(cite);
} Under CSS2, these rules insert a header or footer from a URL into the page. No current browser supports them either:
body:before {
content: url(standardheader.html);
}
body:after {
content: url(standardfooter.html);
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” 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.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg