Forum Moderators: not2easy
If you put the css code in the header of the html document you need to tell the browser that the css part is not text... the browser can see it's not html but it doesn't know what it is... so it usually just displays it as text. Once you put comments around the css, the html parser will ignore it.However, the CSS parser will still find it and follow it, because CSS comments are different from html comments.
Really? I've never had a problem with the browser displaying my styles as text, and I've tested as far back as NN4. I'd be interested in hearing more on this.
Of course, I normally use an external stylesheet anyway, but I'm always looking for new things to learn! ;)
In fact, I would discourage anyone from using HTML style comments.
W3C sheds some additional light on the matter:
Note that XML parsers are permitted to silently remove the contents of comments. Therefore, the historical practice of "hiding" scripts and style sheets within "comments" to make the documents backward compatible is likely to not work as expected in XML-based user agents.
HTML style comments is backward compatibility (for those that have to worry about NN2 and IE2 visitors), a "historical practice".
Forward thinking developers should not use HTML comments inside <style> or <script> tags any more.
If you don't have the comment tags on the page, your javascript and css will be indexed as well.
Is this really the case? It makes much more sense for bots to look at content between tags(ie body, title meta etc.) than it does for them to index everything thats not between html comments.
I think people still comment their styles/scripts out of habit and not because they should. Personally I havent done it in years.
when I did not comment out the style in the header ... my page would not work
That must have been some other temporary glitch. IE6 (and actually ever since IE4) renders CSS fine -- with or without the comments. In fact, the issue at stake is not IE at all. It's certain standards compliant browsers. Since they are allowed to silently remove the contents of HTML comments they do, no matter if the comment happens to be inside a style or script.
As for browsers permitted to silently remove HTML comments when parsing, is this the case for HTML or just in the XHTML spec? - I was under the impression it was the latter... If this is the case, I wouldn't use a comment on an XHTML page, but I would still use one on a HTML 4.01 page.
The issue with comments is only related to XHTML and XML documents.The issue with IE6... I don't think that's related to HomeSite. I use HomeSite as well, and I have never had any problems. Have you tried again since?
And no, I have not yet tried this again, but will. I have just been busy reading css things. Thanks for your reply. It is greatly appreciated.