开发者

CSS selector for nth in a series of immediately adjacent tags

I'm trying to implement a sort of zebra striping, but I want to constrain the eligible tags to those that are immediately adjacent to each other.

For example

<span class="match">a</span>
<span class="match">b</span>
<span class="match">c</span>
<span class="nomatch">d</span>
<span class="match">e&l开发者_如何学Got;/span> 

Kinda sorta CSS that doesn't really work

.match + .match:nth-child(2n){ ... }

The spans a, b and c should be zebra striped because the are immediately adjacent to each other, but e should not. Can nth-child be used in this way?


How about this:

Live Demo

$(".match + .match").each(function() {
    $(this).addClass("stripe").prev().addClass("stripe");
});


:nth-child(even)
:nth-child(odd)

Or are you looking to do something more complex?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜