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

前端 未结 5 875
再見小時候
再見小時候 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:12

    This works in IE9+ but it's not the shortest. @BoltClock's selector is the shortest solution for IE9+. I think this one is marginally easier to understand so I'll leave it as an alternative.

    ul li:first-child a, ul li:nth-child(2) a
    {
       background: none repeat scroll 0 0 biege;
    }
    

提交回复
热议问题