Created
May 15, 2018 03:06
-
-
Save kuroshio/ba2526ffd02946a7d3b4fe0817050098 to your computer and use it in GitHub Desktop.
Example of hierarchical nested counters using ordered lists and SCSS. No JavaScript required. Supports different color for counter and proper indentation for multi-line bullet content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ol> | |
<li>Level 1 list item | |
<ol> | |
<li>Level 2 list item</li> | |
<li>Level 2 list item</li> | |
</ol> | |
</li> | |
<li>Level 1 list item | |
<ol class="lower-roman"> | |
<li>Level 2 list item</li> | |
<li>Level 2 list item | |
<ol class="lower-roman"> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item</li> | |
</ol> | |
</li> | |
<li>Level 2 list item | |
<ol class="upper-roman"> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item</li> | |
</ol> | |
</li> | |
</ol> | |
</li> | |
<li>Level 1 list item | |
<ol> | |
<li>Level 2 list item | |
<ol class="upper-alpha"> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item | |
<ol class="upper-alpha"> | |
<li>Level 4 list item</li> | |
<li>Level 4 list item</li> | |
<li>Level 4 list item</li> | |
</ol> | |
</li> | |
</ol> | |
</li> | |
<li>Level 2 list item | |
<ol class="lower-alpha"> | |
<li>Level 3 list item</li> | |
<li>Level 3 list item | |
<ol class="lower-alpha"> | |
<li>Level 4 list item</li> | |
<li>Level 4 list item</li> | |
<li>Level 4 list item</li> | |
</ol> | |
</li> | |
<li>Level 3 list item</li> | |
</ol> | |
</li> | |
</ol> | |
</li> | |
<li>Level 1 list item | |
<br> | |
<span>There is no list for this item</span> | |
</li> | |
</ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ol { | |
counter-reset: section; | |
> li { | |
display: table; | |
counter-increment: section; | |
&:before { | |
color: #76b900; | |
content: counters(section, ".") ".0"; | |
display: table-cell; | |
padding-right: 10px | |
} | |
} | |
li ol > li:before { | |
content: counters(section, "."); | |
} | |
.lower-roman, | |
.upper-roman, | |
.lower-alpha, | |
.upper-alpha { | |
counter-reset: styledSection; | |
> li { | |
counter-increment: styledSection; | |
} | |
} | |
.lower-roman > li:before { | |
content: counters(styledSection, ".", lower-roman); | |
} | |
.upper-roman > li:before { | |
content: counters(styledSection, ".", upper-roman); | |
} | |
.lower-alpha > li:before { | |
content: counters(styledSection, ".", lower-alpha); | |
} | |
.upper-alpha > li:before { | |
content: counters(styledSection, ".", upper-alpha); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment