Skip to content

Instantly share code, notes, and snippets.

@davidDuymelinck
Last active August 29, 2015 14:17
Show Gist options
  • Save davidDuymelinck/d4fd0a3baee85dfee9b5 to your computer and use it in GitHub Desktop.
Save davidDuymelinck/d4fd0a3baee85dfee9b5 to your computer and use it in GitHub Desktop.
sass vs less
.quanty-query(@number, @comparison, @content) when (@comparison = 'greater'), (@comparison = 'more'), (@comparison = '>'){
&:nth-last-child(n @{number}):first-child {
&,
& ~ * {
@content();
}
}
}
.quanty-query(@number, @comparison, @content) when (@comparison = 'fewer'), (@comparison = 'less'), (@comparison = '<'){
&:nth-last-child(-n @{number}):first-child {
&,
& ~ * {
@content();
}
}
}
.quanty-query(@number, @comparison, @content) when (default()){
&:nth-last-child(@{number}):first-child {
&,
& ~ * {
@content();
}
}
}
@mixin quantity-query( $number, $comparison: 'equal' ) {
@if index( ('greater' 'more' '>'), $comparison ) {
$nth: 'n + #{$number}';
} @else if index( ('less' 'fewer' '<'), $comparison ) {
$nth: '-n + #{$number}';
} @else if index( ('equal' 'same' '='), $comparison ) {
$nth: $number;
} @else {
@warn "Sorry, that’s an invalid $comparison value."
}
&:nth-last-child(#{$nth}):first-child {
&,
& ~ * {
@content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment