【问题标题】:How to print the class, if there is a variable name如果有变量名,如何打印类
【发布时间】:2015-08-18 19:19:22
【问题描述】:

我有一个变量:

@test: this_is_var;

我有课

.my-@{test}-class{}

如何在另一个类中打印这个类?

这段代码是错误的:

.test-class{
    .my-@{test}-class();
}

但是这段代码可以正常工作

.test-class{
    .my-this_is_var-class();
}

为什么?以及如何打印这个类:.my-@{test}-class()?

【问题讨论】:

  • 没有办法(你不能通过“动态名称”调用 mixin,尽管最终计划通过 mixin 引用间接支持)。请参阅#1399 的讨论,了解为什么直接的“mixin 调用中的变量插值”功能将是一种不好的做法。如果您提供您的用例,我很确定我们可以推荐一个更好的解决方案。
  • 提供用例参考!

标签: css less


【解决方案1】:

您的错误变体在 codepen 中效果很好。 也许您必须在变量中写入~{}。 Here is 一个例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多