【问题标题】:Making nth-child work in IE8 and lower让 nth-child 在 IE8 及更低版本中工作
【发布时间】:2012-12-09 00:51:30
【问题描述】:

我正在使用以下代码:

.c-1:first-child, .c-2:first-child, .c-1:nth-child(4n+1) { margin-left: 0; }

效果很好,但我需要为不支持 nth-child 的浏览器(如 IE8)模仿这一点。

我已经尝试使用这个 jQuery 代码来添加一个类,但是没有任何反应,这个代码对吗?

// Support nth child in IE8
$('.c-1:first-child').addClass('remove');
$('.c-2:first-child').addClass('remove');
$('.c-1:nth-child(4n+1)').addClass('remove');

【问题讨论】:

标签: jquery css internet-explorer-8 css-selectors


【解决方案1】:

我建议使用http://selectivizr.com/

对于伪元素 IE8。 我知道它的旧帖子,但也许有些人会觉得它很有用:)

【讨论】:

    【解决方案2】:

    有一个库可以填充 IE 中缺少的 CSS 功能:

    http://code.google.com/p/ie7-js/

    使用IE9版本将根据功能列表访问:nth-child()http://ie7-js.googlecode.com/svn/test/index.html

    【讨论】:

      【解决方案3】:

      不妨看看以下文章:

      http://abouthalf.com/2011/07/06/poor-mans-nth-child-selector-for-ie-7-and-8/

      但所描述的解决方案仅适用于 ie7 和 8,不幸的是,在 ie6 中它不会

      【讨论】:

      • 这看起来很简单,但理想情况下我想要一些更通用的东西,因为我有需要定位的部分、li 和 div
      【解决方案4】:

      您可以为此使用 jQuery 的 .eq(<index>)

      例如:

      $('.c-1').eq(0).addClass('remove');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-15
        • 2013-05-28
        • 1970-01-01
        • 2012-01-19
        • 1970-01-01
        • 2013-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多