wondering how to make the . outside of the $value

@mixin opacity($value) {
    opacity: .$value;
}

How escape that dot .? I want this:

.foo {
    @include opacity(3);
}

To generate this:

.foo {
    opacity: .3;
}
有帮助吗?

解决方案

The correct way to do this is to use division. Using string interpolation just gives you a string, which is unsuitable for passing to Sass functions that expect numbers:

@mixin opacity($value) {
    opacity: $value / 10;
}

.foo {
    background-color: rgba(5, 5, 5, $value / 10);
}

其他提示

Just like this:

@mixin opacity($value){
  opacity: unquote('.#{$value}');
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top