Contenuto CSS Proprietà
Esempio
L'esempio seguente inserisce il valore dell'attributo href tra parentesi dopo ogni elemento <a>:
a::after {
content: " (" attr(href) ")";
}
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
La content
proprietà viene utilizzata con gli
pseudo-elementi ::before e ::after , per inserire il contenuto generato.
Valore di default: | normale |
---|---|
Ereditato: | no |
Animabile: | no. Leggi su animabile |
Versione: | CSS2 |
sintassi JavaScript: | Non puoi dare a un elemento una pseudo-classe usando JavaScript, ma ci sono altri modi per ottenere lo stesso risultato: |
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente la proprietà.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
Sintassi CSS
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Valori di proprietà
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 |
Altri esempi
Esempio
Come aggiungere i colori dei punti elenco per <ul> o <ol> rimuovendo i punti elenco predefiniti e aggiungendo un'entità HTML simile a punti elenco (•):
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 */
}
Pagine correlate
Riferimento CSS: ::prima dello pseudo elemento
Riferimento CSS: ::dopo lo pseudo elemento