Created
July 9, 2014 17:36
-
-
Save chriseppstein/373293534f1fb33b9183 to your computer and use it in GitHub Desktop.
This file contains 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 index-of-last-class($selector) { | |
$index: null; | |
$counter: 1; | |
@each $component in $selector { | |
@if str-index($component, ".") == 1 { | |
$index: $counter; | |
} | |
$counter: $counter + 1; | |
} | |
@return $index; | |
} | |
@function list-slice($list, $start, $end: length($list)) { | |
$new-list: (); | |
@for $i from $start through $end { | |
$new-list: append($new-list, nth($list, $i), list-separator($list)); | |
} | |
@return $new-list; | |
} | |
@mixin increased-specificity($selector) { | |
@if length($selector) > 1 { | |
@warn "Does not work on compound selectors at this time. Keeping the first."; | |
} | |
$selector: nth($selector, 1); | |
$class-index: index-of-last-class($selector); | |
@if $class-index { | |
$before: list-slice($selector, 1, $class-index); | |
$at: nth($selector,$class-index); | |
$after: list-slice($selector, $class-index + 1, length($selector)); | |
$after: if(length($after) > 0, $after, null); | |
@at-root #{$before}#{$at} #{$after} { | |
@content; | |
} | |
} | |
@else { | |
@warn "Cannot increase the specificity of #{$selector}. It does not include a class name."; | |
@content; | |
} | |
} | |
.increase .me .please { | |
@include increased-specificity(&) { | |
content: wow; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment