Last active
August 29, 2015 14:05
-
-
Save shadowmint/df87bd4301f51d963a44 to your computer and use it in GitHub Desktop.
Sass magic
This file contains hidden or 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
@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%; } | |
} | |
} | |
} | |
} |
This file contains hidden or 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
.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