简体   繁体   English

IE 8支持Odd / Even Zebra样式

[英]IE 8 Support for Odd/Even Zebra Styling

Ok, so. 好的,所以。 I know nth-child([:even|:odd]) isn't supported via IE 8. So now I am stuck trying to come up with a method of applying classes equal to odd/even rows. 我知道通过IE 8不支持nth-child([:even|:odd]) 。所以现在我试图想出一个应用等于奇数/偶数行的类的方法。 the way I would using :nth-child . 我会用的方式:nth-child Which I think my method may.. work, however I have an unordered list, with multiple sub unordered lists within, so the zero index seems to be effected by this issue, and doesn't apply correctly 我认为我的方法可能工作,但是我有一个无序列表,其中有多个子无序列表,所以零索引似乎受此问题的影响,并且不能正确应用

I have a jsFiddle example of whats going on to better show the problem. 我有一个jsFiddle示例 ,其中包含了更好地展示问题的方法。 If you notice for example, the example the LI's with "Header 1" and "Header 2" are at the same level, yet they both get the "even" class. 例如,如果您注意到,带有“Header 1”和“Header 2”的LI的示例处于同一级别,但它们都获得“偶数”类。

The goal is for each UL to have its zebra styling applied to its children one level deep, and each subsequent UL and its children do the same. 目标是让每个UL将其斑马造型应用于其深度为一级的儿童,并且每个后续的UL及其子女都会这样做。 Is anyone able to throw me a bone as to how to fix this? 是否有人能够告诉我如何解决这个问题? Currently it seems that its going based off the overall DOM indexing, rather than a per UL (if that makes sense). 目前似乎它的基础是整体DOM索引,而不是每个UL(如果这是有道理的)。

Something like this? 像这样的东西?

$('ul > li:nth-child(odd)').addClass('li_odds');
$('ul > li:nth-child(even)').addClass('li_evens');    

jsFiddle example jsFiddle例子

I think it is worth noting that the problem stems from a small misunderstanding of the css syntax ul > li means "find all li items that are a direct descendant of a ul item. The selected list of items will include all your outer li as well as the inner as they all are direct descendants of a ul . Because of this when jquery is asked to filter by even or odd ( .filter(':odd|:even') ) the list being filtered is larger than you intended and has included items from multiple levels of the DOM hierarchy which causing your striping to occur across multiple levels of the hierarchy rather than on a per ul basis. 我认为这是值得一提的是,问题从语法的CSS的一个小误会茎ul > li的意思是“找到所有li是一个嫡系项目ul项目。项目的选定列表将包括所有的外立以及作为内部因为它们都是ul直接后代。因此,当jquery被要求按偶数或奇数( .filter(':odd|:even') )进行过滤时,被过滤的列表比你想要的大,并且包含来自DOM层次结构的多个级别的项目,这些项目导致条带化在层次结构的多个级别上发生,而不是基于每个ul级别。

The $('ul > li:nth-child(odd|even)') corrects this by limiting the css selection to the list you intend to zebra stripe. $('ul > li:nth-child(odd|even)')通过将css选择限制为您想要斑马条纹的列表来纠正此问题。 The reason this works even in IE8 is because jquery is handling the selection rather than native css and jquery has worked around the IE8 limitation. 甚至在IE8中它的工作原因是因为jquery正在处理选择而不是本机css,并且jquery已经解决了IE8限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM