Using nth-child to style item 4 and onwards

前端 未结 2 422
孤独总比滥情好
孤独总比滥情好 2021-02-04 00:23

I have a list item where I\'d like the 4th item and onwards to have a different background-color.

I\'ve tried the following:

li:nth-child(4)         


        
相关标签:
2条回答
  • 2021-02-04 01:07

    You need to do this

    li:nth-child(n+5) { background-color:blue; }

    Example: http://jsfiddle.net/jasongennaro/2p4e9/1/

    0 讨论(0)
  • 2021-02-04 01:21

    Use :nth-child(n+5) (CSS indexes start at 1).

    Demo: http://jsfiddle.net/nTZrg/1/

    li:nth-child(n+5) {
        background-color:blue;
    }
    
    0 讨论(0)
提交回复
热议问题