Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created December 2, 2013 15:39
Show Gist options
  • Save ttscoff/7751322 to your computer and use it in GitHub Desktop.
Save ttscoff/7751322 to your computer and use it in GitHub Desktop.
Chapter numbers in CSS
body {
counter-reset: chapter; /* create a chapter counter scope */
}
h1:before {
content: "Chapter " counter(chapter) ". ";
counter-increment: chapter; /* add 1 to chapter */
}
h1 {
counter-reset: subchapter; /* set section to 0 */
}
h2:before {
content: counter(chapter) "." counter(subchapter) " ";
counter-increment: subchapter;
}
h2 {
counter-reset: section;
}
h3:before {
content: counter(chapter) "." counter(subchapter) "." counter(section) " ";
counter-increment: section;
}
h3 {
counter-reset: subsection;
}
h4:before {
content: counter(chapter) "." counter(subchapter) "." counter(section) "." counter(subsection) " ";
counter-increment: subsection;
}
h4 {
counter-reset: subsubsection;
}
h5:before {
content: counter(chapter) "." counter(subchapter) "." counter(section) "." counter(subsection) "." counter(subsubsection) " ";
counter-increment: subsubsection;
}
h5 {
counter-reset: subsubsubsection;
}
h6:before {
content: counter(chapter) "." counter(subchapter) "." counter(section) "." counter(subsection) "." counter(subsubsection) "." counter(subsubsubsection) " ";
counter-increment: subsubsubsection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment