2012-03-09 65 views
1

我用Lesscss在客戶端使用它編寫我的CSS(使用編譯器less.js)。Lesscss與守衛混合。語法錯誤

在文檔中有很多守衛用法的例子,但它不適用於我。我不明白,爲什麼...

代碼示例放在這裏:

@import "common-functions.less"; 

// variables 
@minHeaderWidth: auto; 
@maxHeaderWidth: 1200px; 

@minButtonsWidth: 50px; 
@maxButtonsWidth: 75px; 

// Mixins with guards 
.applyHeaderStyles(@headerWidth, @buttonsWidth) when (ispixel(@headerWidth)) { 
    .my-headerElement { 
     width: @headerWidth; 
    } 
} 
.applyHeaderStyles(@headerWidth, @buttonsWidth) when not (ispixel(@headerWidth)) { 
    .my-headerElement { 
     width: @headerWidth; 
     margin: 0 @buttonsWidth; 
    } 
} 

// than I use .applyHeaderWidth in @media queries 
@media screen and (min-width: 1050px) { 
    .applyHeaderStyles(@maxHeaderWidth, @maxButtonsWidth); 
    .my-buttonElement {width: @maxButtonsWidth;} 
} 
@media screen and (max-width: 1049px) { 
    .applyHeaderStyles(@minHeaderWidth, @minButtonsWidth); 
    .my-buttonElement {width: @minButtonsWidth;} 
} 

代碼是由文檔writen。但它不起作用。 當我執行這個代碼,我有語法錯誤:

 
Syntax Error on line 10 
[link to my file] on line 10, column 58: 
10 // Mixins with guards 
11 .applyHeaderStyles(@headerWidth, @buttonsWidth) when (ispixel(@headerWidth)) { 
12  .my-headerElement { 
+0

我已經less.js版本更新至1.2.2。現在它起作用了。 通過鏈接發現的答案: http://stackoverflow.com/questions/9491716/less-js-guards-and-conditionals – VikomiC 2012-03-09 12:16:59

+0

如果您自己找出答案,建議您自己發佈答案並接受答案或標題中標題爲'已解決'的問題。歡迎來到SO !. – 2012-03-10 07:34:11

回答

1

如前所述here,更新到1.2.2 less.js解決了這個問題。

changelog

1.2.0 
Mixin guards