是否可以使用插值字符串引用变量?
我有一个类别列表,我想从中设置背景颜色。我想将背景颜色的值保留为变量。是否可以通过字符串插值引用变量? Sass 向我当前使用此代码抛出“无效 CSS”错误:
/* Category Colors */
$family_wellness_color: #c1d72e;
$lifestyle_color: #f4eb97;
$food_color: #f78f1e;
...
/* Categories */
@each $cat in family_wellness, lifestyle, food
{
.#{$cat}
{
.swatch, .bar
{
background-color: $#{$cat}_color;
}
}
}
可能吗?我真的很感激一些建议!
I have a list of categories, from which I would like to set a background-color. I would like to keep the values for the background colors as variables. Is it possible to reference a variable by string interpolation? Sass is throwing an "Invalid CSS" error on me currently using this code:
/* Category Colors */
$family_wellness_color: #c1d72e;
$lifestyle_color: #f4eb97;
$food_color: #f78f1e;
...
/* Categories */
@each $cat in family_wellness, lifestyle, food
{
.#{$cat}
{
.swatch, .bar
{
background-color: $#{$cat}_color;
}
}
}
Possible? I would really appreciate some advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我能得到的最接近我想要的东西是:
不是最优雅的解决方案,但它确实为我提供了一个可以在其他几个领域重复使用的 mixin。有谁找到一种方法可以提高效率?
Well, the closest I could get to what I wanted was:
Not the most elegant solution, but it does get me a mixin I can re-use in several other areas. Does anyone see a way to make this more efficient?
使用 Rails 3.1,您可以创建如下模板:
screen.css.scss.erb
- 它具有 scss 和 erb 的所有优点。With Rails 3.1, you can create templates like this:
screen.css.scss.erb
- it comes with all the goodness of scss and erb..html:
.scss:
.html:
.scss: