Свойство содержимого CSS
Пример
В следующем примере значение атрибута href вставляется в круглых скобках после каждого элемента <a>:
a::after {
content: " (" attr(href) ")";
}
Другие примеры «Попробуйте сами» ниже.
Определение и использование
Свойство content
используется с
псевдоэлементами ::before и ::after для вставки сгенерированного содержимого.
Значение по умолчанию: | нормальный |
---|---|
Унаследовано: | нет |
Анимация: | нет. Читать об анимации |
Версия: | CSS2 |
Синтаксис JavaScript: | Вы не можете дать элементу псевдокласс с помощью JavaScript, но есть и другие способы получить тот же результат: |
Поддержка браузера
Цифры в таблице указывают на первую версию браузера, которая полностью поддерживает это свойство.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
Синтаксис CSS
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Значения свойств
Value | Description | Example |
---|---|---|
normal | Default value. Sets the content, if specified, to normal, which default is "none" (which is nothing) | |
none | Sets the content, if specified, to nothing | |
counter | Sets the content as a counter | |
attr(attribute) | Sets the content as one of the selector's attribute | |
string | Sets the content to the text you specify | |
open-quote | Sets the content to be an opening quote | |
close-quote | Sets the content to be a closing quote | |
no-open-quote | Removes the opening quote from the content, if specified | |
no-close-quote | Removes the closing quote from the content, if specified | |
url(url) | Sets the content to be some kind of media (an image, a sound, a video, etc.) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Дополнительные примеры
Пример
Как добавить цвета маркеров для <ul> или <ol>, удалив маркеры по умолчанию и добавив объект HTML, который выглядит как маркеры (•):
ul {
list-style: none; /* Remove HTML bullets */
padding: 0;
margin: 0;
}
li {
padding-left: 16px;
}
li::before {
content: "•"; /* Insert content that looks like bullets */
padding-right: 8px;
color: blue; /* Or a color you prefer */
}
Связанные страницы
Справочник по CSS: псевдоэлемент ::before
Справочник по CSS: псевдоэлемент ::after