less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
17.01k stars 3.41k forks source link

Saving selector to a variable #3053

Open influsion opened 7 years ago

influsion commented 7 years ago

We have this solution:

// LESS
.selector {
    @r: ~'.selector';

    &--mode {
        @{r}__block {
            prop: value;
         }
    }
}

// CSS
.selector--mode .selector__block {
  prop: value;
}

I propose to add a feature: writing @r: &; instead of @r: ~".selector"; to get the current selector and save it in any variable.

Examples:

// LESS
.selector {
  @r: &; // .selector
}

.selector {
  &__inner {
    @r: &; // .selector__inner
  }
}

.selector {
  &--modification &__inner {
    @r: &; // .selector--modification .selector__inner
  }
}