csslesslessc

LESS CSS prepend mixin reference with child selector


Is there any way I can use the immediate child selector without having to do it inside the mixin to get the desired result? The real mixin is actually large and I want to be able to reuse it also without having to pollute it with child selectors.

Desired Result

.wrapper > .col-xs-6 {
  width: 50%;
}

Code I have

.wrapper {
    > .mixintest(); //not allowed
}


.mixintest(){
  .col-xs-6{
    width: 50%;
  }
}

Solution

  • move immediate child selector to mixin

    .wrapper {
        .mixintest();
    }
    
    
    .mixintest() {
      > .col-xs-6 {
        width: 50%;
      }
    }
    

    That is the only way that will work according to https://lesscss.org/features/#mixins-feature more specifically this example in "Namespace" subsection

    #outer > .inner(); // deprecated
    #outer .inner();   // deprecated
    #outer.inner();    // preferred