因此,我使用一些相当复杂的Sass从"&“中删除所有其他选择器。
.test, .test-2, .test-3, .test-4 {
$selectors: (&);
@if length(&) != 1 {
$selectors: (); // Works only with Ruby Sass
$i: 1;
@each $item in (&) {
$i: $i + 1;
@if $i % 2 == 0 {
$i: 0;
}@else{
$selectors: append($selectors, $item);
}
}
$selectors: to-string($selectors, ", ");
content: "#{$selectors}";
}
}我对content属性的预期结果是:
content: ".test-2, .test-4";在使用Ruby Sass时,这正是我得到的结果。当使用Libsass时,我得到这个错误:
argument `$list` of `nth($list, $n)` must not be empty 这个错误是指我正在使用的自定义" to -string“函数中的代码:
@function to-string($list, $glue: '', $is-nested: false, $recursive: false) {
$result: null;
@for $i from 1 through length($list) {
$e: nth($list, $i);
@if type-of($e) == list and $recursive {
$result: $result#{to-string($e, $glue, true)};
}
@else {
$result: if(
$i != length($list) or $is-nested,
$result#{$e}#{$glue}, $result#{$e}
);
}
}
@return $result;
}更具体地说,这一行:
$e: nth($list, $i);我传递给to-string函数(即$selectors变量)的值似乎是空的,而实际上它不应该是空的。我最初将它定义为空($selectors: ();),但随后我从&中每隔一项追加一项。所以我不确定为什么在这一点上是空的。
这是一个演示这个问题的Sassmesiter:http://sassmeister.com/gist/332dae9a27983edd9d15
将上述demo中的编译器更改为Libsass,以查看其错误。
我不确定这是我的代码的问题还是Libsass的问题。我不想在Libsass上打开一个问题,除非我确定这是Libsass的问题。
谢谢
发布于 2015-09-04 19:51:31
好了,我已经搞清楚了。很确定这是Libsass的问题。
看起来您不能直接遍历&中的每一项,但是如果我将&存储在一个变量中,它将继续工作。
因此,为了澄清,改变这一点:
@each $item in & {
...
}要这样做:
$this: &;
@each $item in $this {
...
}解决了问题。
https://stackoverflow.com/questions/32396604
复制相似问题