CSS last-child(-1)

前端 未结 2 942
佛祖请我去吃肉
佛祖请我去吃肉 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:09

    Unless you can get PHP to label that element with a class you are better to use jQuery.

    jQuery(document).ready(function () {
      $count =  jQuery("ul li").size() - 1;
      alert($count);
      jQuery("ul li:nth-child("+$count+")").css("color","red");
    });
    

提交回复
热议问题