Created
July 6, 2016 17:43
-
-
Save alexiscordova/f111ff895b30dc85108c3ee5819ba891 to your computer and use it in GitHub Desktop.
Sass mixins to make CSS nth-child selectors easier to work with
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
// Select the first nth elements | |
@mixin first($number) { | |
@if $number == 1 { | |
&:first-child { | |
@content; | |
} | |
} | |
@else { | |
&:nth-child(-n + ${$number}) { | |
@content; | |
} | |
} | |
} | |
// Select the last nth elements | |
@mixin last($number) { | |
&:nth-child(-n + #{$number}) { | |
@content; | |
} | |
} | |
// Select all after nth element | |
@mixin after($number) { | |
&:nth-child(n + ${$number + 1}) { | |
@content; | |
} | |
} | |
// Select every nth element | |
@mixin every($number) { | |
&:nth-child(#{$number}n)) { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment