Less 你能用更少的CSS在mixin中设置一个变量吗?
我知道LESS没有if/else结构,而是依赖于受保护的mixin语句。不过,它似乎无法在mixin中设置更少的CSS变量 任何人都知道我是如何实现某种效果的Less 你能用更少的CSS在mixin中设置一个变量吗?,less,Less,我知道LESS没有if/else结构,而是依赖于受保护的mixin语句。不过,它似乎无法在mixin中设置更少的CSS变量 任何人都知道我是如何实现某种效果的 if( ispercentage( @height ) { @height: "1024px"; } // Calculations dependent on @height @textAreaHeight = 0.5 * @height; @buttonHeight = 0.2 * @height; 我研究了其他几个stacko
if( ispercentage( @height ) {
@height: "1024px";
}
// Calculations dependent on @height
@textAreaHeight = 0.5 * @height;
@buttonHeight = 0.2 * @height;
我研究了其他几个stackoverflow问题,包括:
您可以创建一个由类型“保护”的mixin,例如
.doHeightSet(@height) when ispercentage(@height) {
.doheightSet(1024px)
}
.doHeightSet(@height) when not ispercentage(@height) {
// Calculations dependent on @height
@textAreaHeight: 0.5 * @height;
@buttonHeight: 0.2 * @height;
/* use variables here */
}
抱歉,我没有时间尝试这个,所以我可能犯了语法错误
编辑已更正的语法。是的,可以这样做。有一个bug需要解决 无示例代码
您应该使用:而不是=符号,但您已经知道了。我认为您不能在mixin中设置变量。你能?我试着处理它,但无法得到任何要编译的内容。@blak3r--I无法处理变量的传递。
//Set up guarded mixins
.setHeight(@h) when (ispercentage(@h)) {
@height: 1024px;
}
.setHeight(@h) when not (ispercentage(@h)) {
@height: @h;
}
//set up main height
@mainHeight: 50%;
body { height: @mainHeight;}
//call it by itself to make global
//.setHeight(@mainHeight); <-this failed (appears to be a bug)
.setHeight(50%); // <-this worked
.subsection { height: @height; /* just to show it is setting it */}
//use it for other globals
@textAreaHeight: 0.5 * @height;
@buttonHeight: 0.2 * @height;
textarea { height: @textAreaHeight}
button { height: @buttonHeight}
//override it locally
body.fixedHeight {
.setHeight(300px);
@textAreaHeight: 0.333 * @height;
height: @height;
textarea { height: @textAreaHeight}
}