复合选择器在最后一个闪烁版本中不起作用:nth-​​child(2):nth-​​last-child(2){}

时间:2013-12-02 18:26:09

标签: css webkit css-selectors blink

有一个奇怪的问题:在闪烁更新选择器.groups .group:nth-child(2):nth-last-child(2){}之后才停止工作。 但它仍然适用于webkit和gecko。任何想法如何解决它?

HTML

<div class="groups">
    <div class="group"></div>
    <div class="group"></div>
    <div class="group"></div>
</div>

CSS

.groups .group{
    background-color:#000;
}
.groups .group:first-child{
    background-color:yellow;
}
.groups .group:nth-child(2):nth-last-child(2),
.groups .group:nth-child(2):last-child{
    background-color:red;
}
.groups .group:last-child:nth-child(3){
    background-color:green;
}
.groups{
    font-size:0;
}
.groups .group{
    display:inline-block;
    height:100px;
    width:30px;    
}

您可以在此处查看其工作原理:http://jsfiddle.net/LAq73/1/

如何在blink(chrome)中工作:How it work in blink (chrome)

如何在safari(webkit)中运行:How it work in safari (webkit)

最后FF:How it work in gecko (FF)

任何想法如何解决?

2 个答案:

答案 0 :(得分:2)

使用nth-last-of-type代替nth-last-child保存当天。

.groups .group{
    background-color:#000;
}
.groups .group:first-child{
    background-color:yellow;
}
.groups .group:nth-child(2):nth-last-of-type(2),
.groups .group:nth-child(2):last-child{
    background-color:red;
}
.groups .group:last-child:nth-child(3){
    background-color:green;
}
.groups{
    height:100px;
    font-size:0;
    line-height:0;
}
.groups .group{
    display:inline-block;
    height:100px;
    width:30px;    
}

http://jsfiddle.net/LAq73/3/

答案 1 :(得分:-1)

你太复杂了。

写:

.groups .group:first-child{ /*first child*/
    background-color:yellow;
}
.groups .group:nth-child(2){ /*second child*/
    background-color:red;
}
.groups .group:last-child{ /*last child*/
    background-color:green;
}

Working fiddle here.