在LESS中,我如何将一个混合返回值添加到类的集合中

时间:2013-08-12 03:45:45

标签: css less

例如,假设我有以下内容:

.document {
    header {
        color: blue;
    }
    footer {
        color: red
    }
}

期望的结果:

.my_document {
    .document;
 }

这样的.document;替换为

header {
    color: blue;
}
footer {
    color: red;
}

1 个答案:

答案 0 :(得分:2)

来自http://lesscss.org

  

您也可以使用不带参数的 parametric mixins 。这个   如果要从CSS输出中隐藏规则集,则非常有用,但是   想要将其属性包含在其他规则集中:

.wrap () {   
   text-wrap: wrap;   
   white-space: pre-wrap;  
   white-space:
   -moz-pre-wrap;   word-wrap: break-word; 
}

pre { .wrap }

所以在你的情况下使用:

.document() {
    header {
        color: blue;
    }
    footer {
        color: red
    }
}
.my_document {
    .document;
 }

(尝试在http://less2css.org中运行上述代码)


我不太确定,但我认为在较旧版本的LESS中你必须用括号来调用这些mixins

.my_document {
  .document(); 
}