Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Last active August 29, 2015 14:05
Show Gist options
  • Save shadowmint/df87bd4301f51d963a44 to your computer and use it in GitHub Desktop.
Save shadowmint/df87bd4301f51d963a44 to your computer and use it in GitHub Desktop.
Sass magic
@function str-split($value) {
$rtn: ();
$tmp: $value;
$busy: true;
@while $busy {
$index: str-index($tmp, ' ');
@if $index {
$bit: str-slice($tmp, 0, $index - 1);
$rtn: append($rtn, $bit);
$tmp: str-slice($tmp, $index + 1);
}
@else {
$rtn: append($rtn, $tmp);
$busy: false;
}
}
@return $rtn;
}
@function has-parent($at, $parent) {
@each $item in str_split(#{$at}) {
@if $item == $parent {
@return true;
}
}
@return false;
}
.foo {
.bar {
.other2 {
@if has-parent(&, ".foo") { height: 100%; }
@if has-parent(&, ".other") { width: 100%; }
}
.thing {
.other {
@if has-parent(&, ".other") { width: 100%; }
@if has-parent(&, ".foo") { height: 100%; }
}
}
}
}
.foo .bar .other2 {
height: 100%; }
.foo .bar .thing .other {
width: 100%;
height: 100%; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment