Skip to content

[css-nesting] selecting grandparent selector with @nest  #6977

@lubomirblazekcz

Description

@lubomirblazekcz

The current spec might seem to have missing grandparent selector, which is also very used feature in many preprocessors.

This is currently still possible with postcss-nesting, with noIsPseudoSelector: true option. Which results in following:

.a {
  color: blue;
  & .b {
    @nest :not(.c)& {
      color: red
    }
  }
}

.a:not(.c) .b {
    color: red;
}

This is also the same way Less uses grandparent, and Sass uses @at-rule

.a {
  color: blue;
  .b {
    :not(.c)& {
      color: red
    }
  }
}

.a:not(.c) .b {
    color: red;
}

My question, is this something that should also be added to spec? Becuase I didn't find any mention of this in there. Or should some different syntax be proposed for selecting gradparent selector? Any thoughts on this @tabatkins ?

This issue is also related to grandparent selector - #6330

Also related postcss issue here - csstools/postcss-plugins#195 and supposedly grandselector syntax that previously worked in postcss-nesting was a bug

Current way that works in postcss-nestning is following, which I am not sure if is corect

.a {
  color: blue;
  & .b {
    @nest .a:not(.c) & {
      color: red
    }
  }
}

.a:not(.c) :is(.a .b) {
    color: red;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions