csstools / postcss-nesting

Nest style rules inside each other

Home Page:https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'& + &' cannot work in current version (4.2.1)

superSamChow opened this issue · comments

commented

when I upgraded postcss-cssnext (which contains postcss-nesting) to version 3.0.2 for my project, I found this issue.

when use postcss-cssnext 2.9.0 , all work well.

I have the same issue. How have you solved it?

@jonathantneal Running into a similar issue as well using cssnext, but I can repro on the live example, which I presume is the current version.

Minimal code to reproduce:

div {
  color: #000;
  
  @nest & > & {
   	color: #fff;
  }
}

Expected:

div {
  color: #000;
}
div ~ div {
  color: #fff;
}

Actual is unchanged from the input.

The reason that doesn’t work is because the nesting selector does not represent the parent selector string. It represents the elements it matches.

the nesting selector represents the elements matched by the parent rule
https://tabatkins.github.io/specs/css-nesting/#nest-selector

That means & ~ & is the same as saying “match this particular element when it is a sibling after itself.”