LESS.js + @参数+跳过一个参数
我一直在谷歌等搜索,但我找不到我要找的东西(我希望我没有忽略一些东西)..所以我想我最好的选择就是问你们:)
我正在玩 LESS-JS,我真的很喜欢它。不过我现在有一个小问题。
我正在使用 @arguments
变量,如下所示:
.basicBorder(@width:1px, @type:solid, @color:@black){
border:@arguments;
}
它按预期工作。现在,当我希望边框为红色时,我将其添加到我的 css 中的元素中:
.basicBorder(1px, solid, @red);
这也按预期工作。但是,我想避免编写 1px,solid,
,因为这些已经是我的默认值,但是当我尝试这个:
.basicBorder(@red);
或者这个:
.basicBorder(,,@red);
它不起作用。
所以我想知道是否有任何人知道如何“跳过”前两个变量,以便我可以输入颜色,以防我不希望更改边框宽度和类型。
我希望你明白我想说的!
问候!
I have been searching in Google etc., but I couldnt find what I was looking for (I hope I didnt overlook something).. So I thought my best bet is to ask you guys :)
I am playing around with LESS-JS for the first time and I really like it. However I have a little problem now.
I am using the @arguments
variable like this:
.basicBorder(@width:1px, @type:solid, @color:@black){
border:@arguments;
}
Which works as expected. Now when I want the border to be red, I am adding this to the element in my css:
.basicBorder(1px, solid, @red);
Which also works as expected. However I would like to avoid writing 1px, solid,
, since these are my default values already, but when I try this:
.basicBorder(@red);
Or this:
.basicBorder(,,@red);
It doesnt work.
So I was wondering if any1 knows how I could "skip" the first 2 variables so that I can just input the color in case I dont want the border-width and type to be changed.
I hope you get what I am trying to say!
Regards!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您可以命名后面的参数并跳过前面的参数。您问题的语法是:
您还可以在开头使用正常的有序参数,并从其余参数中提取命名参数:
这将
@width
设置为2px
,@type
为默认值,@color
为@red
。如果您有更多很少使用的参数,那就太好了。You actually can name later parameters and skip the first ones. The syntax for your question is:
You can also use normal ordered arguments at the beginning and pluck out named arguments from the rest of the parameters:
This sets
@width
to2px
,@type
to the default, and@color
to@red
. Really nice if you have more seldom used arguments.LESS 中的参数混合的工作方式有点像 JavaScript 函数,你不能跳过第一个参数。因此,如果您只想更改颜色,您可以像这样重写 mixin:
然后您可以这样调用它:
edit
使用你原来的mixin,你也可以创建这些
现在你可以覆盖任何样式:
有点黑客,但这是我能想到的唯一可以帮助你的东西......
The parametric mixins in LESS works sorta like javascript functions, you can't skip the first parameters. So if you want to only change the color, you could rewrite the mixin like this:
Then you'd be able to call it like this:
edit
Using your original mixin, you could also create these
Now you could overwrite any of the styles:
A bit of a hack, but it's the only thing I can think of to help you out...