sur*_*ajR 24 css compatibility css-selectors internet-explorer-8 ie8-compatibility-mode
我想给我的表行提供斑马条纹效果.在所有其他浏览器中,可以使用CSS第n个子元素完成.但我也想做IE 8.那怎么办呢?
Sam*_*nda 58
使用polyfill:Selectivizr足够好.
没有polyfill:由于IE8支持first-child,你可以欺骗它以支持iE8中的nth-child,即
/*li:nth-child(2)*/
li:first-child + li {}/*Works for IE8*/
Run Code Online (Sandbox Code Playgroud)
虽然我们无法模拟复杂的选择器,即IE8的nth-child(2n + 1)或nth-child(odd).
Jon*_*han 36
作为Selectivizr的替代品,您可以使用一些小jQuery:
$('.your-list li:nth-child(3n+1)').addClass('nth-child-3np1');
Run Code Online (Sandbox Code Playgroud)
然后在CSS中添加第二个选择器:
:nth-child(3n+1)
{
clear: both;
}
.nth-child-3np1
{
clear: both;
}
Run Code Online (Sandbox Code Playgroud)