是否可以在SASS中将变量嵌套在变量内? [英] Is it possible to nest variables within variables in SASS?

查看:73
本文介绍了是否可以在SASS中将变量嵌套在变量内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mixin接受一个我想传递给变量的参数.

@mixin my_mixin($arg) {
  background-color: $state-#{$arg}-text;
}

解决方案

SASS当前无法对变量名进行插值.这是讨论此 https://github.com/nex3/sass/issues/626 的问题 >

但是,您可以使用占位符的插值:

%my-dark-styles {
   background-color: #000;
}
%my-white-styles {
   background-color: #FFF;
}

@mixin my_mixin($arg) {
   @extend %my-#{$arg}-styles;
}

.header {
   @include my_mixin("dark");
}
.footer {
   @include my_mixin("white");
}

它编译为:

.header {
  background-color: #000; }

.footer {
  background-color: #FFF; }

I have a mixin that accepts an argument that I want to pass into a variable.

@mixin my_mixin($arg) {
  background-color: $state-#{$arg}-text;
}

解决方案

Interpolation of variable names is currently not possible in SASS. Here is the issue that discusses this https://github.com/nex3/sass/issues/626

However, you may use interpolation of placeholders:

%my-dark-styles {
   background-color: #000;
}
%my-white-styles {
   background-color: #FFF;
}

@mixin my_mixin($arg) {
   @extend %my-#{$arg}-styles;
}

.header {
   @include my_mixin("dark");
}
.footer {
   @include my_mixin("white");
}

This compiles to:

.header {
  background-color: #000; }

.footer {
  background-color: #FFF; }

这篇关于是否可以在SASS中将变量嵌套在变量内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆