The content property is used to display content in the pseudo-elements ::before and ::after.
Overview tablenormal
content
content: attr
content: close-quote
content: counter
content: no-close-quote
content: no-open-quote
content: none
content: normal
content: open-quote
content: string
content: uri
Double quotation marks cannot occur inside other double quotation marks, unless they are preceded by a backslash (\) escape character. For example, the string "\""
is interpreted as containing one double quotation character.
It is possible to break strings over several lines, for esthetic or other reasons, by use of the backslash as a continuation character; however, the newline character itself is ignored.
Newlines can be used by writing the \A
escape sequence in any of the strings after the content property. The generated line break is displayed in accordance with the value of the white-space attribute.
The backslash is also used to generate escape characters that cannot be represented in the current character encoding. In this case, the backslash is followed by at most six hexadecimal digits (from the range 0–9 and A–F) to indicate the Unicode character with that number.
The counters are rendered in the indicated style (‘decimal’ by default). The name must not be 'none’, ‘inherit’ or 'initial’. Such a name causes the declaration to be ignored.
The following example generates braces before and after all the h1 elements on a page.
h1:before {
content: "{ ";
}
h1:after {
content: " }";
}
Using attr( element-name ) to display text from an attribute. The following example adds a box displaying the value of the data-badge attribute for a button element.
button[data-badge] {
position: relative;
}
button[data-badge]:after {
content: attr( data-badge );
background: tomato;
display: block;
border-radius: 4px;
position: absolute;
right: -4px;
top: -4px;
padding: 1px 4px;
}
Using the uri data-type the webplatform favicon is appended to all elements with the webplatform class.
.webplatform:before {
content: url('/docs/favicon.ico');
}
Uses the counter data-type to show a automatic numbering for all h2 elements on the page. More information is available on the counter-increment property page.
h2 {
counter-increment: header;
}
h2:before {
content: counter(header) ". ";
}
Uses the open-quote and close-quote data-type to add quoting around each blockquote element on the page.
blockquote:before {
content: open-quote;
}
blockquote:after {
content: close-quote;
}
Notes
content
content
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4