views:

411

answers:

5

Given the code (which looks like it should be valid):

<!--[if lt IE 7]> <style type="text/css" media="screen">
<!--
div.stuff { background-image: none; }
--></style><![endif]-->

The W3C validator throws a fit:

  • S separator in comment declaration
  • invalid comment declaration: found name start character outside comment but inside comment declaration
  • character data is not allowed here

etc etc

I'm not totally sure whats going on. Is it the 'nested' comments? The tag is being generated by the Zend Framework Viewhelper headStyle

$this->headStyle()->prependStyle('div.stuff { background-image: none; }',
                                 array('conditional' => 'lt IE 7')
                                );
+6  A: 

You can't have a -- inside of a comment unless it's part of the --> ending in valid XML/XHTML. Just the way comments work.

From this source:

For Compatibility, the string "--" (double-hyphen) MUST NOT occur within comments.

You should find a more standard way to differentiate between browsers (or, more ideally, have a layout that doesn't require differentiation between browsers at all).

Welbog
So commenting out JavaScript elements can break the document? This is odd... The relevant section in the spec is http://www.w3.org/TR/REC-xml/#sec-comments, it states that "for compatibility" means "included solely to ensure that XML remains compatible with SGML".
Tomalak
+3  A: 

"-->" closes any comment, there is no notion of nesting comments inside each other. So in your code, the first "-->" closes both of your comments. Then the <![endif]--> is completely outside of any comments, so doesn't make any sense.

Phil Booth
A: 

It is the nested comments. They are not allowed.

Vincent Ramdhanie
A: 

...and why comment out the entire contents of <style>? It's not as if you're coding for a browser that is dumb enough to display it. (Even command-line browsers hide the style/script blocks.)

Edit: Ah, wait. That's generated by Zend.

grawity
A: 

You should post new issue on issue tracker. It's a good way to make such mistakes corrected. http://framework.zend.com/issues/secure/Dashboard.jspa

Tomáš Fejfar
Thanks, I'll submit a note.
Justin