我在LESS
中写了一个类,它看起来像这样:
.horizontal-gradient (@startColor: #eee, @endColor: white) {
background: linear-gradient(red, yellow);
}
我试图在 LESS
变量中调用它:
@primary-color: .horizontal-gradient(#35a1e5, #0172b9);
但是运行的时候报错
NameError: variable @primary-color is undefined
但是当我这样初始化@primary-color
时:
@primary-color: #000;
然后它就可以正常工作了。所以不知何故,.horizontal-gradient
类导致了错误。
DEMO 我无法让 LESS
在 SO fiddle 中工作。所以我在 jsFiddle 上创建了一个 fiddle 。
<强> http://jsfiddle.net/T2Xe9/828/
如何在变量中使用 LESS
类?
最佳答案
你使用的不是一个变量,而是一个 mixin:http://lesscss.org/features/#mixins-feature .
无需更改 .horizontal-gradient mixin,您可以直接使用它:
div#background {
.horizontal-gradient(#35a1e5, #0172b9);
// The rest of your style
}
因此:您不能将混合结果注册到变量中。
关于css - 如何将 LESS 类添加到 LESS 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46216356/