CSS counter() Funzione
❮ Riferimento alle funzioni CSS
Esempio
Crea un contatore per la pagina (nel selettore del corpo). Incrementa il valore del contatore per ogni elemento <h2> e aggiungi il testo "Sezione < valore del contatore >:" prima di ogni elemento <h2>:
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
La funzione counter() restituisce il valore corrente del contatore denominato, come stringa.
Versione: | CSS3 |
---|
Supporto browser
Function | |||||
---|---|---|---|---|---|
counter() | Yes | Yes | Yes | Yes | Yes |
Sintassi CSS
counter(countername,
counterstyle)
Value | Description |
---|---|
countername | Required. The name of the counter (which is the same name used for the counter-reset and counter-increment properties) |
counterstyle | Optional. The style of the counter (can be a list-style-type value) |
Altri esempi
Esempio
Imposta lo stile del bancone:
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section,
upper-roman) ": ";
}
Pagine correlate
Riferimento CSS: proprietà del contenuto
Riferimento CSS: proprietà contatore-incremento
Riferimento CSS: proprietà di ripristino del contatore
❮ Riferimento alle funzioni CSS