tags:

views:

121

answers:

6

Is it possible for HTML and/or CSS comments to cause rendering problems?

HTML Comment : <!-- some info -->

CSS : /* some info */

A: 

Never had it happen. If you're having problems, you can always validate your HTML and CSS.

Gert G
A: 

I don't recall why, but yes, I've seen that cause a problem in one scenario. In IE, of course. It was an HTML comment.

joelt
Pls try to recall that scenario :)
metal-gear-solid
A: 

On rare occasions I have seen some issues with text ghosting in ie6 because of some comments, but other than that I don't believe any comments (css or html) will cause issues, especially in modern browsers.

Matt
what was that scenario?. pls share
metal-gear-solid
+3  A: 

Not at all, the problem could only occur when you added extra opening or closing letters or even missing sometimes (in which case they are not treated as comments by browser), example:

<!-- some info -->>       // extra >
<!- some info -->         // missing - from begining
<!-- some info --         // missing >

Same goes true for CSS comments.

Sarfraz
@Sarfraz Ahmed - +1 Thanks for this info
metal-gear-solid
@metal-gear-solid: You are welcome :)
Sarfraz
+8  A: 

The comments you have shown wouldn't cause any display issues but if you do:

<!-- My comment ---------- -->

You can run into problems with Firefox. This is because two dashes signal the end of the comment and the > is the end comment marker. So technically this is valid:

<!-- My -- comment >

So what can happen is that your comments aren't ending where you think they should and so some content remained commented out, or the comment displays on the page.

More detail can be found here:

http://weblog.200ok.com.au/2008/01/dashing-into-trouble-why-html-comments.html

Brontojoris
+1 thanks to share the useful info
metal-gear-solid
My problem is solved now . it was http://www.utoronto.ca/web/HTMLdocs/NewHTML/comments.html . I'm selecting your answer because of you gave me a direction.
metal-gear-solid
A: 

Actually we just ran into such an occasion and I'm still looking for a good explanation.

The problem, in fact, was the notorious IE6 drop float bug (triggered with over-sized content in a fixed width floated div). Before I had a look, the designer was convinced that comments were the problem ("but it works when I remove them!"). And she just might be right; my suspicion is that the HTML comments took extra space, the content became over-sized, and as a result, IE6 choked. Although I still can't find anything solid to back my theory yet:)

jodeci
I've seen IE6 be sensitive to white space in HTML before (line breaks), so that could be the situation there.
Alex JL