Skip to content

Instantly share code, notes, and snippets.

@7iomka
Created September 1, 2017 12:44
Show Gist options
  • Save 7iomka/73f4728b8c04d687dac8530e6ad6ad84 to your computer and use it in GitHub Desktop.
Save 7iomka/73f4728b8c04d687dac8530e6ad6ad84 to your computer and use it in GitHub Desktop.
Sass helper function to get the block in the current selector
@function b() {
$selector: str-slice(inspect(&), 2, -2);
@each $type in '__', '--' {
@if str-index($selector, $type) {
$selector: str-slice($selector, 0, str-index($selector, $type) - 1);
}
}
@return $selector;
}
.media {
border: 1px solid;
&__content {
font-size: 10px;
}
&--large {
#{b()}__content {
font-size: 20px;
}
}
}
.media {
border: 1px solid;
}
.media__content {
font-size: 10px;
}
.media--large .media__content {
font-size: 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment