Re: handling of HTML Comments in HTML style element

Christof Höke wrote:
> hope this is the right play to ask, well for the question:
I would guess that this is not the appropriate place, but I’ll answer 
the question anyway.

Christof Höke wrote:
> As far as I understand the spec <!-- and --> in CSS Stylesheets should
> be ignored so it would lead to the following sheet:
>
>               body { color: red }
>               comment
>               body { color: blue }
>               body { color: pink }
>               comment
>               body { color: green }
>
> which definitely has errors in it. But how should the following
> statement be handled now? Ignored as Firefox does it or acknowledged as
> others do it?
I don’t know which part of which CSS specification says that, but 
assuming that you’re right, then the style sheet would be interpreted as:

              body { color: red }
              comment body { color: blue }
              body { color: pink }
              comment body { color: green }

The first rule would be overridden while the second and fourth rules 
would be ignored due to (probably) invalid selectors. Thus, the third 
rule would (probably) be applied and the result would be that the text 
is pink.

I just tried it in Firefox 2 though and that doesn’t seem to be what’s 
happening. If it were, then “<!-- html --> body” would read as “html 
body” and still select the body element. Instead, it seems that Firefox 
ignores “<!--” and “-->” when they are the first and last ((WRT last) 
effectively true even if not really) things in the style sheet. 
Presumably, it’s reading something like:

              body { color: red }
              <!-- comment --> body { color: blue }
              body { color: pink }
              <!-- comment --> body { color: green }

The above code will still result in the text being pink, since “<!-- 
comment --> body” is not a valid selector. Thus, I would presume 
Firefox’s interpretation to be correct.

You might look at 
http://www.webdevout.net/articles/escaping-style-and-script-data for 
some insight. It looks like ECMAScript has some specific provisions for 
ignoring SGML comments, but I don’t see anything similar for style 
elements in the CSS1/2.1/HTML4 specifications. It looks like Firefox is 
doing whatever it does for ECMAScript.

Received on Saturday, 1 September 2007 20:57:45 UTC