W3C home > Mailing lists > Public > www-style@w3.org > September 2007

Re: handling of HTML Comments in HTML style element

From: fantasai <fantasai.lists@inkedblade.net>
Date: Sun, 02 Sep 2007 02:11:16 -0400
Message-ID: <46DA5404.2040005@inkedblade.net>
To: Christof Höke <csad7@t-online.de>
CC: www-style@w3.org

Christof Höke wrote:
> 
> hi,
> hope this is the right play to ask, well for the question:

Yep. Interpretation of the CSS specs is a valid topic here. :)

> How should the following excerpt from a simple HTML page be working:
> 
>       <style type="text/css">
>               body { color: red }
>               <!-- comment -->
>               body { color: blue }
>               body { color: pink }
>               <!-- comment -->
>               body { color: green }
>           </style>
> 
> (see http://cthedot.de/xbrowsertest/css.html for the complete page)
> 
> At least one browser (Firefox) does seem to interpret the spec
> differently than most other browsers (at least IE, Opera, have not
> testet Safari).
> 
> It seems Firefox invalidates the first CSS statement following a HTML
> comment so the resulting text is pinc which is defined in the 2nd
> following statement.

This is defined in CSS2.1 sections 4.1.1
   http://www.w3.org/TR/CSS21/syndata.html#tokenization
and 4.1.9
   http://www.w3.org/TR/CSS21/syndata.html#comments

4.1.9 basically says "refer to the grammar".

The grammar defines the tokens

   CDO  <!--
   CDC  -->

then it defines a style sheet as

   stylesheet  : [ CDO | CDC | S | statement ]*;

where a statement is either a style rule or an @rule.

This means '<!--' and '-->' are allowed anywhere between style rules
and @rules, so your style sheet should result in the following style
rules:

   1. body { color: red }
   2. comment
   3. body { color: blue }
   4. body { color: pink }
   5. comment
   6. body { color: green }

where rules 2 and 3 are invalid because they're each missing a declaration
block. End result: body's color is green.

(At least that is my interpretation. I'm not very well-versed in the
syntax bits, so someone please correct me if I'm wrong. :)

I think this would make a very good test for the test suite, btw. Do
you think you could submit it for inclusion in the CSS2.1 Conformance
Test Suite?
   http://csswg.inkedblade.net/test/css2.1/contribute

~fantasai
Received on Sunday, 2 September 2007 06:11:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:52 GMT