【问题标题】:Why does this not work in IE8? [duplicate]为什么这在 IE8 中不起作用? [复制]
【发布时间】:2014-04-03 16:22:27
【问题描述】:

我必须在 Firefox 和 IE8 中比较我的网站。有一个区别,我就是不明白为什么要这么做。

相信问题出在这行代码

 ul.dropdown > li:last-child {width: 50px;}

有谁知道为什么这可能不起作用? IE8 不喜欢尖括号/ :last-child in CSS

【问题讨论】:

标签: html css firefox internet-explorer-8


【解决方案1】:

:last-child 仅支持 IE >=9

【讨论】:

  • +1 来自我。这是正确的答案。
【解决方案2】:

last-child 选择器在 IE8 及更早版本中不可用。

不过,您可以通过一点 jQuery 魔法来支持这些早期的浏览器:

$("ul.dropdown li:last-child").addClass("last-child");

然后在 css 中你可以这样做:

ul.dropdown li.last-child,
ul.dropdown li:last-child {
    /* Your CSS styling here */
}

只知道样式只会在 jQuery 有机会将类应用到最后一个孩子之后应用。最好将此技术与原始选择器一起使用。

有关 last-child 选择器的更多信息,您可以访问这个有用的页面:

http://www.w3schools.com/cssref/sel_last-child.asp

【讨论】:

    【解决方案3】:

    据我所知,IE8 及以下版本不支持儿童。可能是错的。

    简单的解决方法就是

    <li class="last">List Item</li>
    
    .last {width: 50px;}
    

    【讨论】:

      猜你喜欢
      • 2011-03-27
      • 1970-01-01
      • 2015-06-10
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 2012-12-16
      • 2016-02-29
      • 1970-01-01
      相关资源
      最近更新 更多