LESS包含五個保護比較運算符:<,>,<=,> =和=。 您可以使用比較運算符(=)來比較數(shù)字,字符串,標識符等,而剩余的運算符只能與數(shù)字一起使用。
下面的例子演示了在LESS文件中使用保護比較運算符:
<!doctype html> <head> <title>Guard Comparison Operators</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <h2>Example of Guard Comparison Operators</h2> <p class="myclass">Hello World!!!Welcome to Tutorialspoint...</p> </body> </html>
接下來,創(chuàng)建文件 style.less 。
.mixin (@a) when (@a = 20px){ color:red; } .mixin (@a) when (@a < 20px){ color:blue; } .mixin (@a) { font-size: @a; } .myclass { .mixin(20px) }
lessc style.less style.css
.myclass { color: red; font-size: 20px; }
在 guard_comparison_operators.html 文件中保存上面的html代碼。
在瀏覽器中打開此HTML文件,將顯示如下輸出。
更多建議: