Less.js: "&" includes all parent selectors

Created on 20 Jan 2019  路  2Comments  路  Source: less/less.js

Class name using "&" will include all parent selectors. Only current parent selector should be included.

It's so confusing. If it's an expected behavior, how to write less to output the expected css below?

Less Version: 3.9.0

Less

.wrapper {
  .prefix {
    &-a &-b {
      color: #333;
    }
  }
}

Output CSS

.wrapper .prefix-a .wrapper .prefix-b {
  color: #333;
}

Expected CSS

.wrapper .prefix-a .prefix-b {
  color: #333;
}

All 2 comments

Only current parent selector should be included.

Something that is decided a decade ago and well documented can't be changed just because "it does not fit my particular use-case" (See https://github.com/less/less.js/issues/2395#issuecomment-70136037 for more details).

There're purposes like #1075 that are meant to meant to target a wider range of selector shuffling incl ..your use-case.

Closing in favour of #1075 (and potentially #3053).

If it's an expected behavior, how to write less to output the expected css below?

Currently it's something like:

.wrapper {
    @-: ~'.prefix';
    @{-}-a @{-}-b {
        color: #333;
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

renoth picture renoth  路  6Comments

xblakestone picture xblakestone  路  3Comments

papandreou picture papandreou  路  7Comments

vecerek picture vecerek  路  5Comments

Oskariok picture Oskariok  路  6Comments