-
Notifications
You must be signed in to change notification settings - Fork 26
Nested @media queries not in spec #24
Comments
Good question. @tabatkins, is there intent to allow for nested |
Yes, tho that's not part of my Nesting proposal per se; we already have the fact that at-rules are allowed to next inside of style rules (per spec), we just haven't yet defined any at-rules that are valid in there. But yeah, in an ideal world @media would nest like that. |
@tabatkins @jonathantneal one thing that may be worth considering. Nesting media queries can become somewhat tricky. Given the following: a, b {
@media (min-width: 30em) {
color: yellow;
@media (max-width: 60em) {
color: cyan;
}
}
} This plugin appears to produce: a, b {
}
@media (min-width: 30em) {
a, b {
color: yellow;
}
}
@media (min-width: 30em) and (max-width: 60em) {
a, b {
color: cyan;
}
} That's all well and good, but these queries omit the optional type and negation prefix. So you can't really do something like: a, b {
@media (min-width: 30em) {
color: yellow;
@media not (max-width: 60em) {
color: cyan;
}
}
} Because the resulting CSS isn't really correct: @media (min-width: 30em) and not (max-width: 60em) {
a, b {
color: cyan;
}
} I don't know what you want to do about this, but perhaps it may be best to have this plugin block multiple levels of media query nesting for now as the spec doesn't cover it and it can't always be done correctly. |
Per the latest MQ draft, |
@tabatkins ok, thanks for pointing that out… hadn't seen that draft. |
Thanks @tabatkins. Are the additional wrapping parens required? |
The ones around the |
Is it still expected that nesting |
Sigh. It has taken me years to finally realize that nesting media is not part of any spec. I will need to pull this from the plugin, unless someone wants to take this up with the CSSWG. I will release a new version shortly deprecating the feature but not removing it — in 6.0.0. I’ll set a timer for 3 months to remove it in the subsequent 7.0.0 release. Ideally, by then, some other spec exists to allow this functionality. I’m sorry for accidentally bundling this with the plugin. |
Deprecation published in v6. |
Sorry to add a comment to a closed item, just really disappointing this is not part of the proposed spec. :( Nesting |
Does the plugin support nested media queries now? They appear to be in the spec: |
@martpet it does You can see the test here: https://github.com/csstools/postcss-nesting/blob/main/test/media.css#L5 and the output here https://github.com/csstools/postcss-nesting/blob/main/test/media.expect.css#L9 |
According to the docs, this supports using
@media
rules as a nested selector:However, I don’t see this anywhere in the editor’s draft. I’m not sure if this was pulled from the spec or just added here as a bonus, but this should probably be called out in the documentation (or removed entirely if the intent is to follow the spec as closely as possible).
The text was updated successfully, but these errors were encountered: