是的,它可以做到。有一個錯誤需要解決。
例更少的代碼
//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}
}
範例CSS輸出
body {
height: 50%;
}
.subsection {
height: 1024px; /* just to show it is setting it */
}
textarea {
height: 512px;
}
button {
height: 204.8px;
}
body.fixedHeight {
height: 300px;
}
body.fixedHeight textarea {
height: 99.9px;
}
您應該使用:而不是等號(=),但你已經知道了。 – 2012-07-10 22:16:06