Created
January 13, 2015 14:16
-
-
Save orbmis/30572cc099531c206552 to your computer and use it in GitHub Desktop.
Create nested ordered lists with LESS, automatically prefixing sub-list items
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
/** | |
* Creates nested ordered lists, for example: | |
* | |
* <h1>First Section</h1> | |
* <ol> | |
* <li></li> | |
* <li></li> | |
* <li></li> | |
* </ol> | |
* <h1>Second Section</h1> | |
* <ol> | |
* 1. First Section | |
* 1.1 first sub item | |
* 1.2 second sub item | |
* 1.3 second sub item | |
* 2. Second Section | |
*/ | |
#ilist (@i) when (@i > 9) { | |
& ol:nth-of-type(@{i}) > li:before { | |
content:'@{i}.'; | |
margin: 0 20px 0 -42px; | |
} | |
& ol:nth-of-type(@{i}) > li:nth-of-type(n+10):before { | |
content:'@{i}.'; | |
margin: 0 28px 0 -40px; | |
} | |
#ilist (@i - 1); | |
} | |
#ilist (@i) when (@i < 10) and (@i > 0) { | |
& ol:nth-of-type(@{i}) > li:before { | |
content:'@{i}.'; | |
margin: 0 21px 0 -34px; | |
} | |
& ol:nth-of-type(@{i}) > li:nth-of-type(n+10):before { | |
content:'@{i}.'; | |
margin: 0 28px 0 -40px; | |
} | |
#ilist (@i - 1); | |
} | |
#ilist (0) {} | |
#nested-ordered-lists { | |
&-wrapper { | |
overflow: hidden; | |
} | |
#ilist (20); | |
#ilist (9); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment