Complex selector don't work in last blink version :nth-child(2):nth-last-child(2){}

蹲街弑〆低调 提交于 2019-12-02 02:10:56

问题


there is strange problem: after blink update selector .groups .group:nth-child(2):nth-last-child(2){} just stop working. But it still works well in webkit and gecko. Any ideas how to fix it?

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;    
}

You may see how it work here: http://jsfiddle.net/LAq73/1/

How it work in blink (chrome):

How it work in safari (webkit):

And finaly FF:

Any ideas how to fix it?


回答1:


Usage of nth-last-of-type instead nth-last-child save the day.

.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/




回答2:


You are making it too complex.

Write:

.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.



来源:https://stackoverflow.com/questions/20335187/complex-selector-dont-work-in-last-blink-version-nth-child2nth-last-child2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!