Created
June 22, 2018 17:53
-
-
Save norbert-codes/b696af8dada4241e751132fee243b005 to your computer and use it in GitHub Desktop.
Bump specificity in CSS with Sass (from: https://www.sassmeister.com/gist/01743ade0575313d44b05ff5ca25c076)
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
| // ---- | |
| // libsass (v3.5.4) | |
| // ---- | |
| // A sass mixin to produce a specificity bump on a selector by chaining it | |
| @mixin specificity-bump($specificity: 1) { | |
| $selector: "#{&}"; | |
| @for $i from 1 through $specificity { | |
| $selector: $selector + "#{&}"; | |
| } | |
| @at-root #{unquote($selector)} { | |
| @content; | |
| } | |
| } | |
| .foo { | |
| @include specificity-bump { | |
| color: red; | |
| } | |
| } | |
| #bar { | |
| @include specificity-bump(3) { | |
| color: blue; | |
| } | |
| } | |
| [baz] { | |
| @include specificity-bump(5) { | |
| color: green; | |
| &:not(input) { | |
| color: yellow; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment