CSS last-child(-1)

前端 未结 2 918
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 20:34

I am looking for a css selector that lets me select the pre-last child of list.

  • 1
  • 2
2条回答
  •  無奈伤痛
    2020-12-22 21:17

    You can use :nth-last-child(); in fact, besides :nth-last-of-type() I don't know what else you could use. I'm not sure what you mean by "dynamic", but if you mean whether the style applies to the new second last child when more children are added to the list, yes it will. Interactive fiddle.

    ul li:nth-last-child(2)
    

提交回复
热议问题