gpt4 book ai didi

html - LESScss if 条件变量不为空

转载 作者:行者123 更新时间:2023-11-28 17:27:40 25 4
gpt4 key购买 nike

如果变量不等于 null,我将尝试为 div 添加字体系列。我的 less 代码是

div.content {
& when (isstring(@contentFont)) {
font-family: @contentFont;
}
}

我从 css 得到的输出是

div.content when (isstring(@contentFont)) {
font-family: Abel;
}

我的问题是,样式不适用于 div.content,不确定我做错了什么。任何帮助将不胜感激。

最佳答案

如评论中所述,您使用的是 lessphp 0.4.0 版——它似乎不支持 the shorthand guard (when) syntax你正在尝试使用。

好像是does support guards on mixins , 然而。

尝试将您的代码拆分为一个 mixin 和该 mixin 的用法,如下所示:

/* the mixin */

.fontIfString(@font) when (isstring(@font)) {
font-family: @font;
}

/* usage */

@contentFont: "hello";

div.content {
.fontIfString(@contentFont);
}

关于html - LESScss if 条件变量不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26829347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com