The CSS reference
"content" - css property (v. css 2)
- Used with the ':before' and ':after' pseudo-elements, to insert generated content.
- Initial value: normal
- The property is not inherited
- HTML usage: :before and :after pseudo-elements
-
Browsers that support the content - property :
Browser deviation:- To work in IE, a DOCTYPE must be declared.
Possible content values:
content value | Comments | CSS |
---|---|---|
none | The pseudo-element is not generated. | 2 |
normal | Computes to 'none' for the ':before' and ':after' pseudo-elements. | 2 |
[string] | Text content. | 2 |
[uri] | The value is a URI that designates an external resource (such as an image). | 2 |
[counter] | Counters may be specified with two different functions: 'counter()' or 'counters()'. The former has two forms: 'counter(name)' or 'counter(name, 'list-style-type' )'. The latter function also has two forms: 'counters(name, string)' or 'counters(name, string, 'list-style-type' )'. The generated text is the value of all counters with the given name in scope at this pseudo-element, from outermost to innermost separated by the specified string. Counters are denoted by case-sensitive identifiers (see the 'counter-increment' and 'counter-reset' properties). | 2 |
open-quote | Refers to the first of a pair of 'quotes' . Which pair of quotes is used depends on the nesting level of quotes: the number of occurrences of 'open-quote' in all generated text before the current occurrence, minus the number of occurrences of 'close-quote'. | 2 |
close-quote | Refers to the second pair of 'quotes' . Which pair of quotes is used depends on the nesting level of quotes: the number of occurrences of 'open-quote' in all generated text before the current occurrence, minus the number of occurrences of 'close-quote'. | 2 |
no-open-quote | Inserts nothing, but increments the quotation depth by one. | 2 |
no-close-quote | Decrements the quoting level, but does not insert a quotation mark. | 2 |
attr(X) | This function returns as a string the value of attribute X for the subject of the selector. If the subject of the selector does not have an attribute X, an empty string is returned. | 2 |
inherit | Will inherit the value from parent specification. | 2 |
Property "content" example:
<!DOCTYPE HTML >
<html>
<head>
<title>Page title</title>
<style type="text/css">
p.note:before {
content: "Note:";
font-weight: bold;
}
p#first:after {
content: " (you cannot use tags in content property)";
color: red;
}
</style>
</head>
<body>
<p id="first"> This is the first paragraph.
<p class="note"> :after and :before
plays with CSS content property.
</body>
</html>
Javascript access:
// To SET values ([o] is the target object)
[o].style.content="content values"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.content;
/* The returned value is not cross-browser reliable.
The value can vary in accuracy and notation,
which depends on the browser, whether the value is preset or not
and which option that was used to set the value.*/
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.