The content property
The content property allows you to
insert arbitrary generated text into tags. It
is used together with
after
and
before
pseudo-elements.
Syntax
cssselector::after {
content: 'text';
}
cssselector::before {
content: 'text';
}
Example
Let's insert additional text at the
start and end of the li tag
text:
html<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>cssli::before {
content: '!!!';
}
li::after {
content: '???';
}
Результат:
Example
You can apply different styles to inserted text. Let's color this text in some color, for example:
html<ul>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
<li>list item</li>
</ul>cssli::before {
color: red;
content: '!!!';
}
li::after {
color: green;
content: '???';
}
Результат:
See also
-
the
attrfunction
that gets a value of a tag attribute -
the
counter-incrementproperty
that sets automatic numbering