Penghitung CSS () Fungsi
Contoh
Buat penghitung untuk halaman (di pemilih isi). Tambahkan nilai penghitung untuk setiap elemen <h2>, dan tambahkan teks "Bagian < nilai penghitung >:" sebelum setiap elemen <h2>:
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Fungsi counter() mengembalikan nilai saat ini dari counter bernama, sebagai string.
Versi: kapan: | CSS3 |
---|
Dukungan Peramban
Function | |||||
---|---|---|---|---|---|
counter() | Yes | Yes | Yes | Yes | Yes |
Sintaks 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) |
Lebih Banyak Contoh
Contoh
Mengatur gaya penghitung:
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section,
upper-roman) ": ";
}
Halaman Terkait
Referensi CSS: properti konten
Referensi CSS: properti counter-increment
Referensi CSS: properti counter-reset