Created
May 6, 2013 09:43
-
-
Save lunelson/5524240 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com, the Sass playground.
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
// automatic adjacent selector generation | |
$heading-blocks: h1 h2 h3 h4 h5 h6; | |
$other-blocks: p, ul, ol; | |
@mixin adjacent($list:()) { | |
@if $list == () { // self-adjacent, if no list provided | |
& + & { @content; } | |
} @else { // takes space or comma separated list of single elements | |
$arr: unquote("#{nth($list, 1)} + &"); | |
@for $n from 2 through length($list) { | |
$arr: append($arr, unquote(", #{nth($list,$n)} + &")); | |
} | |
#{$arr} { @content; } | |
} | |
} | |
.test { | |
@include adjacent { | |
color: blue; | |
} | |
@include adjacent($heading-blocks) { | |
color: green; | |
} | |
@include adjacent($other-blocks) { | |
color: red; | |
} | |
} |
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
.test + .test { | |
color: blue; | |
} | |
h1 + .test, h2 + .test, h3 + .test, h4 + .test, h5 + .test, h6 + .test { | |
color: green; | |
} | |
p + .test, ul + .test, ol + .test { | |
color: red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment