Skip to content

Instantly share code, notes, and snippets.

@marcialca
Created November 9, 2012 01:14
Show Gist options
  • Save marcialca/4043090 to your computer and use it in GitHub Desktop.
Save marcialca/4043090 to your computer and use it in GitHub Desktop.
[CSS]CSS Count Increment
.box {
counter-increment: boxes;
}
The counter-increment property can accept either one or two properties. The first is an id that you will later use to reference this specific counter. You may also pass a second parameter that refers to the increment. For example, instead of 1, 2, 3, 4, you could switch to 5, 10, 15, 20 by applying: counter-increment: boxes 5.
This code will now store a unique number for each element that has a class of box. But of course, we want to get this number on the page. Hopefully, we’ll, at some point in the future, be able to use the content property within standard selectors, but not quite yet. Instead, we’ll use pseudo elements to apply the content.
.box:after {
content: counter(boxes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment