CSS -inhoud Eigenschap
Voorbeeld
In het volgende voorbeeld wordt de waarde van het href-attribuut tussen haakjes ingevoegd na elk <a>-element:
a::after {
content: " (" attr(href) ")";
}
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De content
eigenschap wordt gebruikt met de
::before en ::after pseudo-elementen om gegenereerde inhoud in te voegen.
Standaardwaarde: | normaal |
---|---|
geërfd: | Nee |
Animeerbaar: | Nee. Lees over animeren |
Versie: | CSS2 |
JavaScript-syntaxis: | Je kunt een element geen pseudo-klasse geven door JavaScript te gebruiken, maar er zijn andere manieren om hetzelfde resultaat te krijgen: |
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de eigenschap volledig ondersteunt.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
CSS-syntaxis
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Eigendomswaarden
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 |
Meer voorbeelden
Voorbeeld
Kleuren voor opsommingstekens toevoegen voor <ul> of <ol> door hun standaard opsommingstekens te verwijderen en een HTML-entiteit toe te voegen die eruitziet als opsommingstekens (•):
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 */
}
Gerelateerde pagina's
CSS-referentie: ::voor pseudo-element
CSS-referentie: ::na pseudo-element