gpt4 book ai didi

less - 如何在 LESS 中使用 if 语句

转载 作者:数据小太阳 更新时间:2023-10-29 09:10:19 27 4
gpt4 key购买 nike

我正在寻找某种 if 语句来控制不同 div 元素的 background-color

我已经尝试了下面的,但是它没有编译

@debug: true;

header {
background-color: (yellow) when (@debug = true);
#title {
background-color: (orange) when (@debug = true);
}
}

article {
background-color: (red) when (@debug = true);
}

最佳答案

有一种方法可以为单个(或多个)属性使用守卫。

@debug: true;

header {
/* guard for attribute */
& when (@debug = true) {
background-color: yellow;
}
/* guard for nested class */
#title when (@debug = true) {
background-color: orange;
}
}

/* guard for class */
article when (@debug = true) {
background-color: red;
}

/* and when debug is off: */
article when not (@debug = true) {
background-color: green;
}

...还有 Less 1.7;编译为:

header {
background-color: yellow;
}
header #title {
background-color: orange;
}
article {
background-color: red;
}

关于less - 如何在 LESS 中使用 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910667/

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