Description
I suspect this has already been discussed before but I cannot find any trace of it.
If I am not mistaken, &
is valid in the prelude of a top-level style rule and represents :root
. So it is theoretically valid to use a <relative-selector-list>
like > body
.
Would it be acceptable to define the prelude of top-level style rules with <relative-selector-list>
instead of <selector-list>
?
If so, changes would be required in CSS Syntax 3 (8.1. Defining Block Contents: the <declaration-list>
, <rule-list>
, and <stylesheet>
productions) and CSSOM (parse a selector and serialize a selector).
Obviously, that does not seem usefull. I am actually interested in having a single style rule definition to simplify the representation of CSS rule definitions.
The block value of @scope
is defined with <stylesheet>
, which accepts all CSS rules except those excluded by @scope
or restricted to a specific context (eg. keyframe, margin, etc).
For all other CSS rules whose block value is <stylesheet>
, this is equivalent to accepting all top-level rules excluding @import
and @namespace
.
But the prelude of (scoped) style rules in @scope
is defined with <relative-selector-list>
(like nested style rules) therefore valid rules in @scope
need to be explicitly defined rather than defining a list of excluded rules, which is otherwise matching the intent of the formal definition of <stylesheet>
in CSS Syntax 3 (emphasize added):
For rules that use
<stylesheet>
, all rules are allowed by default, but the spec for the rule may define what types of rules are invalid inside the rule.
the
<stylesheet>
production represents a list of rules. It is identical to , except that blocks using it default to accepting all rules that aren’t otherwise limited to a particular context.
https://drafts.csswg.org/css-syntax-3/#declaration-rule-list