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

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

问题描述

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

@mixin my_mixin($arg) {背景颜色:$state-#{$arg}-text;}

解决方案

目前在 SASS 中无法插入变量名.这是讨论此问题的问题 https://github.com/nex3/sass/issues/626>

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

%my-dark-styles {背景色:#000;}%my-white-styles {背景颜色:#FFF;}@mixin my_mixin($arg) {@extend %my-#{$arg}-styles;}.header {@include my_mixin("dark");}.页脚{@include my_mixin("white");}

这编译为:

.header {背景色:#000;}.页脚{背景颜色:#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天全站免登陆