Last active
August 2, 2018 12:37
-
-
Save certainlyakey/89f0feb17a6a2399983cc09d01e04b45 to your computer and use it in GitHub Desktop.
Last parent selector in SASS (like & but only the last one)
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
// same as &, but applies the last (closest) parent only | |
// usage: @include u-direct-parent('.parent'<, ...>) {} | |
@mixin u-direct-parent($parent-selectors...) { | |
@each $parent-selector in $parent-selectors { | |
$current-sequences: &; | |
$new-sequences: (); | |
@each $sequence in $current-sequences { | |
$current-selector: nth($sequence, -1); | |
$prepended-selector: join($parent-selector, $current-selector); | |
$new-sequence: set-nth($sequence, -1, $prepended-selector); | |
$new-sequences: append($new-sequences, $new-sequence, comma); | |
} | |
@at-root #{$new-sequences} { | |
@content; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From here: https://stackoverflow.com/a/30687813/102397