Propriété de contenu CSS
Exemple
L'exemple suivant insère la valeur de l'attribut href entre parenthèses après chaque élément <a> :
a::after {
content: " (" attr(href) ")";
}
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La content
propriété est utilisée avec les
pseudo-éléments ::before et ::after , pour insérer le contenu généré.
Valeur par défaut: | Ordinaire |
---|---|
Hérité: | non |
Animable : | non. En savoir plus sur l'animation |
Version: | CSS2 |
Syntaxe JavaScript : | Vous ne pouvez pas donner à un élément une pseudo-classe en utilisant JavaScript, mais il existe d'autres façons d'obtenir le même résultat : |
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la propriété.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
Syntaxe CSS
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Valeurs de propriété
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 |
Plus d'exemples
Exemple
Comment ajouter des couleurs de puces pour <ul> ou <ol> en supprimant leurs puces par défaut et en ajoutant une entité HTML qui ressemble à des puces (•) :
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 */
}
Pages connexes
Référence CSS : ::before pseudo-élément
Référence CSS : ::after pseudo-élément