CSS - Inhaltseigenschaft
Beispiel
Das folgende Beispiel fügt den Wert des href-Attributs in Klammern nach jedem <a>-Element ein:
a::after {
content: " (" attr(href) ")";
}
Weitere „Probieren Sie es selbst“-Beispiele weiter unten.
Definition und Verwendung
Die content
Eigenschaft wird mit den
Pseudoelementen ::before und ::after verwendet, um generierte Inhalte einzufügen.
Standardwert: | normal |
---|---|
Vererbt: | Nein |
Animierbar: | Nein. Lesen Sie mehr über animierbare |
Ausführung: | CSS2 |
JavaScript-Syntax: | Sie können einem Element keine Pseudo-Klasse zuweisen, indem Sie JavaScript verwenden, aber es gibt andere Möglichkeiten, dasselbe Ergebnis zu erhalten: |
Browser-Unterstützung
Die Zahlen in der Tabelle geben die erste Browserversion an, die die Eigenschaft vollständig unterstützt.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
CSS-Syntax
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Eigenschaftswerte
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 |
Mehr Beispiele
Beispiel
So fügen Sie Aufzählungszeichenfarben für <ul> oder <ol> hinzu, indem Sie ihre Standardaufzählungszeichen entfernen und eine HTML-Entität hinzufügen, die wie Aufzählungszeichen aussieht (•):
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 */
}
Verwandte Seiten
CSS-Referenz: ::before Pseudoelement
CSS-Referenz: ::after Pseudo-Element