W3C home > Mailing lists > Public > www-style@w3.org > August 2001

Re: At-rules (@-rules) in @media blocks

From: Tantek Celik <tantek@cs.stanford.edu>
Date: Sat, 11 Aug 2001 17:20:30 -0700
To: Bjoern Hoehrmann <derhoermi@gmx.net>
CC: Boris Zbarsky <bzbarsky@MIT.EDU>, "www-style@w3.org" <www-style@w3.org>
Message-ID: <1214546943-417568619@psdbay.com>
Bjoern Hoehrmann had the best example of the same argument being made in the
last three messages, so I'm only going to respond to message in the thread.

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Subject: Re: At-rules (@-rules) in @media blocks
Date: Sat, Aug 11, 2001, 2:28 PM

> * Tantek Celik wrote:
>>> So I don't see where forbidding @page in @media makes CSS easier to
>>> implement
>>In CSS2, there is no nesting of @-rules at all.  This greatly simplifies
>>@-rule parsing code.  Parsing something of 1-depth is much easier to code
>>(read less code, less chance for buggy code etc.) than parsing something of
> Consider
>   @media screen
>   {
>     @rule1 { @rule2 "}" { @rule3 { content: "}" } } }
>     h1 { color: green }
>   }
> How do you parse that accoding to the forward-compatibility rules
> without parsing the nested at-rules?

Easy, you parse the curly braces and the strings (to make sure the braces
inside quotes don't affect the current unknown brace depth), and throw them
away.  That's all that is required here.

The unknown @-rules are irrelevant and ignored.

> In order to ignore some token,
> you _must_ parse it to know where it ends and according to the generic
> syntax you _must_ parse nested at-rules.

Nope.  Again, just nested curly braces and strings.

> I agree that it is simpler to parse one-level nesting than to parse
> abitrary levels of nesting but CSS Level 2 doesn't offer this option,
> you _must_ parse it. CSS Level 2 even offers more evil possible
> constructs:
>   elem { newval: @foo ";}" @bar "{" @baz "@x" { @polar { uri('#') } } }
> I fear to test what current parsers do with this ruleset.

No problem - bring it on.

Again, just nested curly braces strings.  It is _very_ easy to parse an
arbitrary depth of unknown braces and throw away everything you're seeing in
the mean time.

> I would agree with you, if CSS Level 2 forbid to nest at-rules in the
> generic grammar, than you wouldn't have to cope with them, but CSS2
> didn't so parsers have to deal with it in order to be forward-compatible
> and therefore CSS2 compliant.

Not quite.  It is much more difficult to give those arbitrary brace depths
some meaning (e.g. nested @media blocks), than to keep track of a depth
counter and just throw stuff away while parsing.

>>If you could nest 15 levels of @-rules, style sheets would begin looking
>>like C++ files, and I don't think you want that.
> You won't tell me, that having 15 different style sheets and a base
> style sheet with 15 @import rules in order to import all those style
> sheets is much simpler and I doubt there are cases where it is
> desireable to habe 15 levels of nesting in CSS.

Precisely correct.  Both are bad constructs.

However, having them in the same file gives the illusion of being easy, and
thus authors walk down the path before they realize the mess they have

All this being said, I can see some utility for having @page inside @media,
or even @media inside @media, but I'm not sure how often I'd use it.  If you
really think it would be that useful, I invite you to make a proposal for


Can I get the icon in cornflowerblue?
Absolutely.                        http://www.w3.org/TR/css3-color#x11-color
Received on Saturday, 11 August 2001 20:19:55 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:26:58 UTC