jQuery:odd和:nth-​​child CSS3不同 [英] jQuery :odd and :nth-child CSS3 different

查看:179
本文介绍了jQuery:odd和:nth-​​child CSS3不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现jQuery:odd selector和CSS3 nth-child(odd)工作不同。
http://jsfiddle.net/TMDwT/5/

I found that jQuery :odd selector and CSS3 nth-child(odd) works different. http://jsfiddle.net/TMDwT/5/

在黄色的CSS是第n个孩子(奇数),如果你取消注释JS和注释背景:黄色在CSS中,你会发现它在另一种方式找到。

In yellow it's CSS nth-child(odd) and if you uncomment JS and comment background: yellow in CSS you will find that it found in another way.

任何人都可以说我如何在jQuery中实现相同的结果,但是使用CSS3?

Can anybody say how I achieve the same result as in jQuery but with CSS3?

谢谢!

推荐答案

是,:奇数和< a href =http://api.jquery.com/nth-child-selector/ =nofollow>:nth-​​child(odd)不一样的东西:


  • :odd 匹配匹配元素即

  • :odd matches the odd items within the matched elements, i.e. the contents of the jQuery object you apply the selector to,

:nth-​​child(odd)

这与:第一个:first-child :last :last-child

更新:由于zzzzBov和BoltClock out,:odd 选择器是从零开始的,但是:nth-​​child()选择器是从1开始的。这意味着,即使你将两个选择器应用到一个元素的完整子列表中(从而消除了:odd :nth-​​child (odd)),它们仍然不会匹配相同的元素。

Update: As zzzzBov and BoltClock rightfully point out, the :odd selector is zero-based but the :nth-child() selector is one-based. This means that even if you apply the two selectors to the complete child list of an element (thus removing the difference between :odd and :nth-child(odd)), they still won't match the same elements.

这篇关于jQuery:odd和:nth-​​child CSS3不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆