Re: [csswg-drafts] [css-nesting-1] Yet another nesting proposal (#7970)

> Even if optional, I hope & is still allowed?

No, not on a nested rule. The `&` in this proposal indicates that the following block is a collection of style properties that apply to the selector on the at-rule (and we could do this without the `&` entirely, in which case I wouldn't allow it as optional even there).

As I said, by default, everything inside a `@nest` is a style rule relative to the selector on the rule itself.

My original thought was to not even allow properties inside at all, e.g.:
```
foo {
  color: blue;
}
@nest foo {
  bar { color: red; }
}
```
but having to repeat the first selector seemed an unnecessary redundancy. 

The main issue with all the other proposals is that style rules expect properties, and the syntax for properties has way too many collisions with selectors, so a carve-out for allowing selectors gets cumbersome. 

This proposal makes a new kind of style rule that expects nested style rules, the carve-out is to allow properties within a limited scope.

Another detail that I didn't mention originally, by default there's an ancestor combinator between the `@nest` selector and nested selectors. There's no reason that the `@nest` selector couldn't end with a combinator, or the nested rules could start with a combinator (probably not both tho).

E.g.:
```
@nest foo > {
   bar { ... }
   baz { ... }
}
```
would be equivalent to:
```
foo > bar { ... }
foo > baz { ... }
```
and
```
@nest foo {
  > bar { ... }
  + baz { ... }
}
```
would be equivalent to:
```
foo > bar { ... }
foo + baz { ... }
```


-- 
GitHub Notification of comment by plinss
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7970#issuecomment-1294062187 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 27 October 2022 21:06:47 UTC