LESS mix-in for nth-child?

后端 未结 1 883
庸人自扰
庸人自扰 2021-02-05 09:49

I\'m trying to make a LESS mixin that will give me this output:

.resource:nth-child(8n+1) { clear: left; }

I\'ve got this so far:



        
相关标签:
1条回答
  • 2021-02-05 10:28

    Less >= 1.4

    you could do something like this:

    .wrap-every(@n) {
      &:nth-child(@{n}n + 1) {
            clear: left;
        }
    }
    

    this should have the desired output. Without any hacks needed.

    in older versins of Less

    you can try simple string interpolation:

    .wrap-every(@n) {
        @t: ~":nth-child(@{n}n + 1)";
        &@{t} {
            clear: left;
        }
    }
    

    and the output CSS in both cases should be something like this:

    .resource:nth-child(8n + 1) {
      clear: left;
    }
    
    0 讨论(0)
提交回复
热议问题