小编San*_*len的帖子

使用LESS变量作为属性而不是值

我制作了以下两个Mixins:

.responsive_color(@color, @response_color, @speed: 0.1s){
     color:                  @color;
    .transition(color, @speed);

    &:hover, &:active, &:focus{
        color:                  @response_color;
    }
}

.responsive_background(@color, @response_color, @speed: 0.1s){
    background-color:       @color;
    .transition(background-color, @speed);

    &:hover, &:active, &:focus{
        background-color:       @response_color;
    }
}
Run Code Online (Sandbox Code Playgroud)

由于这两个几乎是相同的,所以我想将它们组合成如下形式:

.responsive(@property, @color, @response_color, @speed: 0.1s){
    @property:              @color;
    .transition(@property, @speed);

    &:hover, &:active, &:focus{
        @property:                  @response_color;
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然这不会在LESS解析器(PHP类)中引起错误,但将其忽略。我也尝试过@ {property}和'@ {property}',但两者都会导致错误。

有谁知道我如何输出@property进行正确解析?还是我试图做一些不可能的事情?

mixins less

3
推荐指数
1
解决办法
3070
查看次数

标签 统计

less ×1

mixins ×1