Is it possible to select the last n items with nth-child?

前端 未结 5 2279
猫巷女王i
猫巷女王i 2020-12-02 09:04

Using a standard list, I\'m trying to select the last 2 list items. I\'ve various permutations of An+B but nothing seems to select the last 2:

l         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 09:37

    This will select the last two iems of a list:

    li:nth-last-child(-n+2) {color:red;}
    • fred
    • fred
    • fred
    • fred
    • fred
    • fred
    • fred
    • fred
    • fred
    • fred

提交回复
热议问题