SASS/SCSS 中从变量值获取变量名
我想使用定义的值在 @each
循环中访问变量,如下例所示:
$car:true;
$people:false;
$job:false;
@mixin options($someval){
@each $prefix in car,people,job{
@if $#{$prefix} == true{
//some CSS...
}
}
}
变量将是一种定义是否打印 Css 规则的“信号量”。
我最大的疑问是如何检查动态定义的变量名称?
我尝试过 $#{$prefix}
但它不起作用。
编辑 - - - - - - - - - - - - - - 我想获得这个 CSS
car-something: 34px;
其中“car”一词取自 $prefix
并在第一轮 @each
循环中 $#{$prefix }
变成 $car
问题出在 $#{$prefix}
...它不起作用:P 我收到错误
I'd like to access variable within an @each
loop using defined value like in the following example:
$car:true;
$people:false;
$job:false;
@mixin options($someval){
@each $prefix in car,people,job{
@if $#{$prefix} == true{
//some CSS...
}
}
}
Variable would be a sort of "semaphores" that define whether print or not Css rules.
My big doubt is how can I check over dynamically defined variables name ?
I've tried with $#{$prefix}
but it doesn't work.
EDIT ---------------------------
I'd like to obtain this CSS
car-something: 34px;
Where the word "car" is taken from $prefix
and in the first round of @each
loop $#{$prefix}
becomes $car
The problem is on $#{$prefix}
... it doesn't work :P i get an error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个老问题,但由于它没有有效的答案,所以这里是
您需要将地图传递给
@each
This is an old question but since it has no valid answer, here it is
You need to pass a map to
@each
不要尝试插入变量名,而是将列表传递给 mixin。
Instead of trying to interpolate a variable name, pass a list to the mixin.