Select last child when odd, 2 last childs when even

后端 未结 3 987
失恋的感觉
失恋的感觉 2020-12-31 14:01

I\'m in a situation where the number of elements showed is variable, and I need a strange solution which I\'m not able to achieve, I even doubt if it\'s achievable only with

3条回答
  •  清酒与你
    2020-12-31 14:43

    Here is one way...

    .wrap div:last-child,
    .wrap div:nth-last-of-type(-n+2):not(:nth-child(even)) {
        color: red;
    }
    Odd
    Even
    Odd
    Even
    Odd
    Even

    Odd
    Even
    Odd
    Even
    Odd

提交回复
热议问题