CSS last-child selector: select last-element of specific class, not last child inside of parent?

前端 未结 6 773
夕颜
夕颜 2020-11-22 01:45
6条回答
  •  野的像风
    2020-11-22 02:32

    Something that I think should be commented here that worked for me:

    Use :last-child multiple times in the places needed so that it always gets the last of the last.

    Take this for example:

    .page.one .page-container .comment:last-child {
      color: red;
    }
    .page.two .page-container:last-child .comment:last-child {
      color: blue;
    }

    When you use .comment:last-child

    you only get the last comment in both parents

    Something

    Something

    Something

    Something

    When you use .page-container:last-child .comment:last-child

    you get the last page-container's, last comment

    Something

    Something

    Something

    Something

提交回复
热议问题