Skip to content

Instantly share code, notes, and snippets.

@lunelson
Created June 4, 2013 09:15
Show Gist options
  • Save lunelson/5704708 to your computer and use it in GitHub Desktop.
Save lunelson/5704708 to your computer and use it in GitHub Desktop.
Contains and Contains-Any
// ---
// Sass (v3.2.9)
// ---
// testing containment of any of multiple keys in a complex list
@function contains-any($list, $keys...) {
$result: false;
@each $key in $keys {
@each $item in $list {
@if length($item) > 1 {
$result: $result or contains-any($item, $keys...);
} @else if index($item, $key) {
$result: true;
}
}
}
@return $result;
}
$testlist: body 5, heading (blue red, green yellow);
.test {
contains: contains-any($testlist, green);
contains2: contains-any(red blue yellow, green);
}
.test {
contains: true;
contains2: false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment