Using :nth-child and :nth-last-child simultaneously

徘徊边缘 提交于 2019-12-24 00:14:53

问题


I can't make :nth-child and :nth-last-child pseudo-classes work simultaneously.

Works well (highlights first 3 elements):

#a li:nth-child(-n+3) {
   background: #fbfcc8; 
}

Works well (highlights last 3 elements):

#b li:nth-last-child(-n+3) {
   background: #fbfcc8; 
}

Doesn't work (highlights first 3 elements and last one):

#c li:nth-child(-n+3), #c li:nth-last-child(-n+3) {
   background: #fbfcc8; 
}

http://jsfiddle.net/8GSQ6/2/

Update:

In real I have more complicated HTML, so seems like it's just a bug.


回答1:


Try this:

    #c1 li:nth-child(-n+3), #c1 li:nth-last-child(-n+3) {
       background: #fbfcc8; 
    }

This works for me..

Change id to c1.




回答2:


It's just a bug in Google Chrome 31.0.1650.57 for Mac. Firefox, Safari and latest Google Chrome works well.



来源:https://stackoverflow.com/questions/20346681/using-nth-child-and-nth-last-child-simultaneously

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