收录日期:2019/08/18 17:20:47 时间:2010-06-16 12:50:58 标签:html,css,comments

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

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

CSS : /* some info */

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

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.

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.

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

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.

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:)

I had this problem just now: a web page disappeared when viewed on the Kindle Fire (Safari). When I took out the comment, the page came back. I tested this three times. Nothing else was changed, and the comment tag wasn't missing anything, as far as I know. (I just checked it; not sure how to post code here, but it matched the sample above.)

Oh, and I don't think it could be "too much content," as theorized by Jodeci--I stripped my site down to nothing but a navbar and two divs, because I was trying to figure out why it kept disappearing.