Skip to content

[syntax-3] are at-rules allowed to nest inside of style rules #2752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jonathantneal opened this issue Jun 9, 2018 · 3 comments
Closed

[syntax-3] are at-rules allowed to nest inside of style rules #2752

jonathantneal opened this issue Jun 9, 2018 · 3 comments
Labels
Closed Rejected as Invalid Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-syntax-3 Testing Unnecessary Memory aid - issue doesn't require tests

Comments

@jonathantneal
Copy link
Contributor

Are at-rules allowed to nest inside of style rules, per spec? If so, where is this defined?

Example usage:

body {
  margin: 20px;

    @media (min-width: 30em) {
        margin: 0;
    }
}

I’m asking because folks confuse this with being part of the nesting proposal. And, for my own part, I didn’t help disambiguate this (csstools/postcss-nesting#24).

@AmeliaBR
Copy link
Contributor

According to the most basic syntax parsing model, yes, an at-rule can be nested within a declaration list. However, that doesn't mean it will have an effect; as the note in the spec says, most at-rules will be ignored in a declaration list:

Unexpected at-rules (which could be all of them, in a given context) are invalid and should be ignored by the consumer.

So you need to find the spec that defines the at-rule in question, to see where it may be "expected". For @media (and also @supports), the reference definition is in CSS Conditional Rules, which states:

Conditional group rules are allowed at the top-level of a style sheet, and inside other conditional group rules. CSS processors must process such rules as described above.

So, an @media or @supports rule would currently be unexpected & invalid inside a declaration list.

But you could definitely make a proposal for a CSS Conditional Rules Level 4!

@jonathantneal
Copy link
Contributor Author

Thank you, @AmeliaBR! I’m sure this information will help me (and other spec-minded folks) very soon.

@fantasai
Copy link
Collaborator

Yeah, as @AmeliaBR says, there's no at-rule that's currently valid within a style rule. But we did modify the syntax to make sure that one there would be properly “ignored” by the parser, for forwards-compatibility with any future such at-rules.

@fantasai fantasai changed the title [selectors-4] are at-rules allowed to nest inside of style rules [syntax-3] are at-rules allowed to nest inside of style rules Jun 11, 2018
@tabatkins tabatkins added Closed Rejected as Invalid Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. Testing Unnecessary Memory aid - issue doesn't require tests labels Jan 24, 2019
@tabatkins tabatkins added this to the CSS Syntax 3 June 2019 CR milestone Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Rejected as Invalid Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-syntax-3 Testing Unnecessary Memory aid - issue doesn't require tests
Projects
None yet
Development

No branches or pull requests

4 participants