nth-child() or first-child? how to select first AND second child in one

前端 未结 5 957
再見小時候
再見小時候 2020-12-24 13:25

I\'d like to select the first two list items in an unordered list. I can select the first item thus:

ul li:nth-child(1) a {
    background: none repeat scrol         


        
5条回答
  •  再見小時候
    2020-12-24 14:08

    For selecting the first and second children, you can use a single :nth-child() pseudo-class like so:

    ul li:nth-child(-n+2) a {
        background: none repeat scroll 0 0 beige;
    }
    

提交回复
热议问题