- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Thu, 06 Jun 2019 19:16:51 +0000
- To: public-css-archive@w3.org
The reason I didn't like `@switch` equivalents is that it still only lets you test on a single *type* of conditional at a time. If you want to test for a MQ *and* an SQ, or else do something else, you can't write that reasonably in `@switch`.
That is:
```css
@switch {
@media A {
@supports B {
/* code intended for (A && B) */
}
}
@media not A {
/* code intended for (!A)
aka (!A && B) or (!A && !B) */
}
@default {
/* code intended for (A && !B),
the leftover case */
}
}
```
will *never* run the @default block (because the two top-level rules fully cover `A` and `not A`), even if the intention is to have it contain code for when A is true but B is false.
Versus when/else, which would handle it well:
```css
@when media(A) and supports(B) {
/* (A && B) */
}
@else media(not A) {
/* (!A), which is (!A && B) || (!A && !B) */
}
@else {
/* (A && !B) */
}
```
I don't think it's possible to mod `@switch` into doing this, because the top-level rules aren't constrained to contain only a single child conditional; it could have several, so you can't easily tell what cases it's supposed to cover (and thus what "default" should cover).
--
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/112#issuecomment-499630643 using your GitHub account
Received on Thursday, 6 June 2019 19:16:53 UTC