admin管理员组文章数量:1303454
Is there a way to pass a variable by reference in a LESS mixin?
.test-mixin(@varname)
{
test-prop: @@varname; // Works, test-prop is 5.
@@varname: 7; // Error
}
:root
{
@test-var: 5;
.test-mixin(test-var);
--test: @test-var; // I want it to be 7 here.
}
Why do I need this? I have the following mixin:
.assert-image-is-square(@src)
{
// assert_eq is a plugin, that throws an exception and breaks compilation.
assert_eq(image-width(@src), image-height(@src));
}
…and want it to also change a given @size
:
@box_size: dummy;
.assert-image-is-square('images/box.png', @box_size);
Is there a way to pass a variable by reference in a LESS mixin?
.test-mixin(@varname)
{
test-prop: @@varname; // Works, test-prop is 5.
@@varname: 7; // Error
}
:root
{
@test-var: 5;
.test-mixin(test-var);
--test: @test-var; // I want it to be 7 here.
}
Why do I need this? I have the following mixin:
.assert-image-is-square(@src)
{
// assert_eq is a plugin, that throws an exception and breaks compilation.
assert_eq(image-width(@src), image-height(@src));
}
…and want it to also change a given @size
:
@box_size: dummy;
.assert-image-is-square('images/box.png', @box_size);
Share
Improve this question
asked Feb 4 at 14:40
ShtoleShtole
3482 silver badges15 bronze badges
1
- I hope no one else will edit your code except you. – imhvost Commented Feb 4 at 21:22
1 Answer
Reset to default 0So far, the best shot is to declare variables within the mixin and use them outside:
.test-mixin(@varname)
{
test-prop: @varname; // Do something.
@res-1: 7;
@res-2: 8;
}
:root
{
@test-var: 5;
@result: .test-mixin(@test-var);
--test-1: @result[@res-1]; // 7
--test-2: @result[@res-2]; // 8
}
本文标签: cssPassing a variable by reference in a LESS mixinStack Overflow
版权声明:本文标题:css - Passing a variable by reference in a LESS mixin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741758500a2396256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论