有一个奇怪的问题:在闪烁更新选择器.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)中工作:
如何在safari(webkit)中运行:
最后FF:
任何想法如何解决?
答案 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;
}
答案 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;
}