简体   繁体   中英

Sass mixin with class name as variable and :lang()

i am trying create mixin. Something like this

 @mixin localesRule($class, $cssProp, $value) {
        .#{$class:lang(pt)}, //...other locales { 
            $cssProp: $value;
        }
    }

But got error... Can someone help me? It is possible to do this?

@mixin localesRule($class, $cssProp, $value) {
  #{$class}:lang(pt), #{$class}:lang(pl), #{$class}:lang(sk), #{$class}:lang(mx), #{$class}:lang(pt-BR) {
    #{$cssProp}: $value;
  }
}

.foo {
  &-button {
    @include localesRule('&', padding-right, 0);
  }
}

output:

.foo-button:lang(pt), .foo-button:lang(pl), .foo-button:lang(sk), .foo-button:lang(mx), .foo-button:lang(pt-BR) {
  padding-right: 0;
}

Don't know what you exactly expect, here are a few basic examples in SCSS . Let's assume you have a class like this.

.login {}

Now create a mixin you want to use in the class.

@mixin main-button($parent-selector, $property, $selector, $size-value) {
    #{$parent-selector}__img {
        width: 100px;
        #{$property}: left;
    }

    #{$selector} {
        background: none;
    }

    &__button {
        font-size: $size-value;
    };
}

Use the mixin in the class.

.login {
    @include main-button(&, float, "text", 14px);
}

The output should be like this.

.login {
    .login__img {
        width: 100px;
        float: left;
    }

    .text {
        background: none;
    }

    .login__button {
        font-size: 14px;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM