如何将 LESS class 添加到 LESS 变量?
How to add a LESS class to a LESS variable?
我在LESS
里写了一个class,长这样:
.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
class 导致了错误。
DEMO 我无法让 LESS
在 SO fiddle 中工作。所以我在 jsFiddle 上创建了一个 fiddle。
http://jsfiddle.net/T2Xe9/828/
如何在变量中使用 LESS
class?
你使用的不是一个变量,而是一个 mixin:http://lesscss.org/features/#mixins-feature.
无需更改 .horizontal-gradient mixin,您可以直接使用它:
div#background {
.horizontal-gradient(#35a1e5, #0172b9);
// The rest of your style
}
因此:您不能将混合结果注册到变量中。
我在LESS
里写了一个class,长这样:
.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
class 导致了错误。
DEMO 我无法让 LESS
在 SO fiddle 中工作。所以我在 jsFiddle 上创建了一个 fiddle。
http://jsfiddle.net/T2Xe9/828/
如何在变量中使用 LESS
class?
你使用的不是一个变量,而是一个 mixin:http://lesscss.org/features/#mixins-feature.
无需更改 .horizontal-gradient mixin,您可以直接使用它:
div#background {
.horizontal-gradient(#35a1e5, #0172b9);
// The rest of your style
}
因此:您不能将混合结果注册到变量中。