Last active
August 29, 2015 14:16
-
-
Save iamnewton/4dbe153b2272a73b9744 to your computer and use it in GitHub Desktop.
Mixin to Qualify a Selector (https://css-tricks.com/snippets/sass/mixin-to-qualify-a-selector/)
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
.button { | |
border: none; | |
} | |
button.button { | |
-webkit-appearance: none; | |
} | |
a.button { | |
text-decoration: none; | |
} |
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
// ---- | |
// Sass (v3.4.12) | |
// Compass (v1.0.3) | |
// ---- | |
/// Since the current way to qualify a class from within its ruleset is quite | |
/// ugly, here is a mixin providing a friendly API to do so. | |
/// @author Hugo Giraudel | |
/// @param {String} $element-selector - Element selector | |
@mixin qualify($element-selector) { | |
@at-root #{$element-selector + &} { | |
@content; | |
} | |
} | |
/// @alias qualify | |
@mixin when-is($args...) { | |
@include qualify($args...) { @content; } | |
} | |
.button { | |
border: none; | |
// Qualify `.button` with `button` | |
@include qualify(button) { | |
-webkit-appearance: none; | |
} | |
// Qualify `.button` with `a` | |
@include when-is(a) { | |
text-decoration: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment