发送属性作为mixin的参数 [英] Send properties as argument for mixin

查看:108
本文介绍了发送属性作为mixin的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要分解所有的媒体查询,并将CSS属性作为参数传递。

 。 bp1(@css){
@media(max-width:959px){
@css
}
}

.bp1(width:186px ;);不幸的是,这不会工作,并使得失败:(


关于mixins的LESS文档说:Mixins允许你通过将类名称作为其一个属性来将一个类的所有属性嵌入到另一个类中。它就像变量,但是对于整个类,Mixins也可以像函数一样运行,并接受参数,如下面的例子所示。



但css属性和它们的值,在一个mixin中由一个变量声明或表示,所以你想做的是无效的。


I'd like to break out all of my Media-queries and pass the CSS properties as arguments instead.

.bp1(@css){
    @media (max-width: 959px){
        @css
    }
}

.bp1(width: 186px;);

Unfortunately, this wont work and makes the Less fail :(

解决方案

The LESS documentation about mixins says: "Mixins allow you to embed all the properties of a class into another class by simply including the class name as one of its properties. It’s just like variables, but for whole classes. Mixins can also behave like functions, and take arguments, as seen in the example bellow."

You can't have anything but css properties and their values, either stated or represented by a variable, in a mixin. So what you're trying to do is invalid.

这篇关于发送属性作为mixin的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆