问题
This is just question about comments inside of an HTML page.
For example:
<html>
<head></head>
<body>
<!--
<p><font size="4">--</font></p>
-->
</body>
</html>
Using http://validator.w3.org/check I get the following error message. Does it make sense?
Line 6, Column 21: invalid comment declaration: found character "<" outside comment but inside comment declaration
<p><font size="4">--</font></p>
Check that you are using a proper syntax for your comments, e.g: . This error may appear if you forget the last "--" to close one comment, and later open another.
回答1:
Yes, it makes sense.
To understand the error message, you have to understand the comment tag. It consists of three key parts, the <!
that starts the tag, the --
that starts and ends the comment, and the >
that ends the tag.
When you put --
inside the text of a comment, you actually end the comment part. The rest of the text until the end of the tag is invalid, as it's not a comment, and you can only have comments inside the comment tag.
You can also have more than one comment in the tag:
<!-- comment -- -- another comment -->
回答2:
Looks like the string --
isn’t allowed within HTML comments.
回答3:
No, it does intuitively not make sense to most of the logical thinking humans, but the validator has it really right. The --
denotes a comment delimiter. Also see W3 validator bug 5555:
yes, really invalid. -- is a comment delimiter in XML.
回答4:
I think it's being confused by the two hyphens in the middle. The ones in >--<.
If you must have those, perhaps you could substitute the escape character -
for them.
来源:https://stackoverflow.com/questions/3320350/why-does-the-html-validator-give-me-an-error-about-this-html-comment