W3C home > Mailing lists > Public > www-style@w3.org > April 2015

Re: [css-cascade][mediaqueries] Allow custom mq before @import?

From: Glen Huang <curvedmark@gmail.com>
Date: Wed, 15 Apr 2015 19:50:41 +0800
Cc: www-style list <www-style@w3.org>
Message-Id: <934DB51A-7E89-46E9-B6F5-B021E8998340@gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
I see the rationale. Thanks.

You mentioned the possibility of custom media being redefined. I can't help but wonder how it works:

@import "def.css";
@import "redef.css" (--foo);
@import "foo.css" (--foo);

@custom-media --foo true;

@custom-media --foo false;

Will this cause "foo.css" not being imported?

Also, being able to using custom media in other places sounds wonderful, but does it have to be specified in a <meta>? Could a <style>, placed at an early position of <head>, containing the custom media definitions, be enough to make the custom media queries available document wide?

> On Apr 8, 2015, at 8:37 AM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> On Wed, Apr 1, 2015 at 10:21 PM, Glen Huang <curvedmark@gmail.com> wrote:
>> Currently, the CSS Cascading and Inheritance Level 4 spec says the only rule allowed before @import is @charset. I wonder if custom mq could be allowed too?
>> ```css
>> @custom-media --narrow-window (max-width: 30em);
>> @import “style.css” (--narrow-window);
>> ```
> I get where you're coming from, but this partially defeats the purpose
> of the "@import must come first" restriction, which is to keep the
> interleaving of imported stylesheets simple.  Right now, you can
> pretend that @import'd stylesheets are completely separate sheets that
> appear just before the importing sheet in document order (except for
> the effects of @charset).  This makes implementation simpler - all
> rules/etc from a given sheet are guaranteed to be totally before/after
> the rules in any other sheet, not interleaved in ways that require
> more complicated tracking.
> If we allowed @custom-media first, though, then we have to worry about
> this more complicated interleaving, since the imported sheet might
> define --narrow-window as well (overriding the definition in the
> importing sheet).  This isn't circular or anything, but it is
> complicated in ways that we currently don't have to handle in
> implementations.
> That said, I think it's valuable to be able to use custom MQs in very
> wide contexts, including in HTML (for <link media>, <picture><source
> media></picture>, etc), and so I think I need to define a <meta> value
> that defines a custom MQ as well, so you can easily define
> document-wide MQs.  (This would also make them accessible to the
> preload scanner for <picture> purposes, which is great.)
> ~TJ
Received on Wednesday, 15 April 2015 11:51:14 UTC

This archive was generated by hypermail 2.4.0 : Monday, 23 January 2023 02:14:50 UTC