以下のように、1 つの基本クラスでループ (保護された mixin を使用して作成) を使用できます。基本クラスには共通のプロパティがあり、必要に応じてループ内から何度でも拡張できます。
フォーム形式で CSS を作成するには、基本クラスと拡張が必要.x1, .x2, .x3{}
です。のようにできる場合.x1{} .x2{}
、基本クラスと拡張は実際には必要ありません。
.x1{ //base class with all common props
color: blue;
}
.fancymixin(@max, @prefix) when (@max > 1) { // loop from 10 to 1
.fancymixin(@max - 1, @prefix); // call the next iteration of the loop
.@{prefix}@{max}:extend(.x1){}; // extend the properties of the x1 base class
}
.fancymixin(10, x);
コンパイル済み CSS:
.x1,
.x2,
.x3,
.x4,
.x5,
.x6,
.x7,
.x8,
.x9,
.x10 {
color: blue;
}
注:.fancymixin(10, y)
同じ mixin を呼び出して別のループ ( など) を作成し、グループの個別のプロパティ セットを作成する場合、上記のアプローチは機能しません。.y*
これは、常に.x1
クラス プロパティを拡張しているためです。