Skip to content

Instantly share code, notes, and snippets.

@terkel
Last active January 25, 2020 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terkel/d60c0111ff4d107500c82940f8fede53 to your computer and use it in GitHub Desktop.
Save terkel/d60c0111ff4d107500c82940f8fede53 to your computer and use it in GitHub Desktop.
// lang-is()
// Creates selector matches any of language tags
//
// @param {list} $langs - List of labguage tags to match
//
// @example
// @include lang-is(ja, ko, zh) {
// font-kerning: none;
// }
// p {
// @include lang-is(ja, ko, zh) {
// font-family: sans-serif;
// }
// }
//
// @output
// :lang(ja), :lang(ko), :lang(zh) {
// font-kerning: none;
// }
// p:lang(ja), p:lang(ko), p:lang(zh) {
// font-family: serif;
// }
@mixin lang-is ($langs...) {
$selector: ();
$parent: if(&, "&", "");
@each $lang in $langs {
$selector: append($selector, "#{$parent}:lang(#{$lang})", $separator: comma);
}
#{$selector} {
@content;
}
}
// lang-not()
// Creates selector does not matche any of language tags
//
// @param {list} $langs - List of labguage tags not to match
//
// @example
// @include lang-not(ja, ko, zh) {
// font-kerning: auto;
// }
// p {
// @include lang-not(ja, ko, zh) {
// font-family: serif;
// }
// }
//
// @output
// :not(:lang(ja)):not(:lang(ko)):not(:lang(zh)) {
// font-kerning: auto;
// }
// p:not(:lang(ja)):not(:lang(ko)):not(:lang(zh)) {
// font-family: serif;
// }
@mixin lang-not ($langs...) {
$selector: if(&, "&", "");
@each $lang in $langs {
$selector: $selector + ":not(:lang(#{$lang}))";
}
#{$selector} {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment