5
我不知道Sass是否能夠做到這一點,但它並沒有傷害問。Sass Mixin:回調或替換@content
的問題
基本上我有中的重複應用的多個部分,像blue
,和orange
三種顏色圖案。有時,什麼樣的變化是background-color
,或組件的border-color
......有時是文本的子元素的color
等
我想什麼?
1.替換內容中的字符串模式。
.my-class {
@include colorize {
background-color: _COLOR_;
.button {
border-color: _COLOR_;
color: _COLOR_;
}
}
}
2.提供回調變量@content
。
// This is just a concept, IT DOESN'T WORK.
@mixin colorize {
$colors: blue, green, orange;
@each $colors in $color {
// ...
@content($color); // <-- The Magic?!
// ...
}
}
// Usage
@include colorize {
background-color: $color;
}
我想實現這樣的解決方案,但都沒有成功。
而不是它...
見下面我解決方法得到它的部分工作:
@mixin colorize($properties) {
$colors: blue, green, orange;
@for $index from 1 through length($colors) {
&:nth-child(#{length($colors)}n+#{$index}) {
@each $property in $properties {
#{$property}: #{nth($colors, $index)};
}
}
}
}
您可以使用此混入這樣:
.some-class {
@include colorize(background-color);
}
什麼會輸出:
.some-class:nth-child(3n+1) {
background-color: blue;
}
.some-class:nth-child(3n+2) {
background-color: green;
}
.some-class:nth-child(3n+3) {
background-color: orange;
}
的問題?那麼,我不能用它選擇兒童。
基於以上信息,對於這種情況下,一些神奇的解決方案?
它看起來像重寫而不使用「@content」,但它可能使用「@content」? – llamerr
https://github.com/sass/sass/issues/871 – llamerr