问题描述
|
我正在尝试实现一种斑马条纹,但我想将符合条件的标签限制为彼此紧邻的标签。
例如
<span class=\"match\">a</span>
<span class=\"match\">b</span>
<span class=\"match\">c</span>
<span class=\"nomatch\">d</span>
<span class=\"match\">e</span>
Kinda sorta CSS确实不起作用
.match + .match:nth-child(2n){ ... }
跨度a,b和c应该是斑马条纹的,因为彼此紧邻,但是e不应。可以以这种方式使用nth-child吗?
解决方法
这个怎么样:
现场演示
$(\".match + .match\").each(function() {
$(this).addClass(\"stripe\").prev().addClass(\"stripe\");
});
,:nth-child(even)
:nth-child(odd)
还是您想做些更复杂的事情?