CSS 字符串中的 SASS 变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22385157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SASS Variable within string
提问by Mark
Hi all I'm new to SASS (late I know) and playing around with mixins.
大家好,我是 SASS 的新手(我知道的晚了)并且正在使用 mixin。
Basically is there a way to link a variable to a string here is what I'm trying to do but it throws errors. (This is a condensed version)
基本上有一种方法可以将变量链接到字符串,这是我正在尝试做的,但它会引发错误。(这是精简版)
@mixin post-link ($class, $color, $hover) {
a.$class:link {
color: $color;
}
a.$class:hover {
color: $hover;
}
}
Link I say this is a little simpler than what I am trying to do in the mixin (more variables in full one).
Link 我说这比我在 mixin 中尝试做的要简单一些(完整的变量更多)。
EDIT: should add i'm using Compass. Thanks
编辑:应该添加我正在使用指南针。谢谢
回答by KatieK
Yes, you just have to use variable interpolation. Example:
是的,您只需要使用变量插值。例子:
@mixin post-link ($class, $color, $hover) {
a.#{$class}:link {
color: $color;
}
a.#{$class}:hover {
color: $hover;
}
}
Example on SassMeister: http://sassmeister.com/gist/9533103
SassMeister 示例:http://sassmeister.com/gist/9533103
The key is adding #{
and }
around your variable names to get them expanded.
关键是添加#{
并}
围绕您的变量名称来扩展它们。