Tuesday, September 14, 2010

Commenting your work

The rules for HTML, CSS, and JavaScript comments are simple, but the actual characters
used are different in each case.
HTML comments begin with <!-- and end with -->, and can run over multiple lines, as
follows:
<!-- this is a comment in HTML -->
<!--
Multiple-line
HTML
comment
-->
In XHTML, double hyphens should not occur within the comment itself. Therefore, the following
is not valid XHTML:
<!-- This is invalid -- as is the comment below -->
<!--------------------------------------------------------->
The multiple-hyphen comment is commonly used by designers who favor hand-coding to
separate large chunks of code within a document. When working in XHTML, you can
replace the hyphens with a different character:
<!--oooooooooooooooooooooooooooooooooooooo-->
<!--================================-->
CSS comments were covered in the “Creating boilerplates” section of Chapter 1, but we’ll
briefly look through them again; they’re opened with /* and closed with */ and, like HTML
comments, can run over multiple lines, as shown here:
/* This is a comment in CSS */
/*
Multiple-line
CSS
comment
*/
Multiple-line comments in JavaScript are the same as in CSS, but single-line comments are
placed after double forward slashes:
// This is a single-line JavaScript comment.
Don’t use comments incorrectly. CSS comments in an HTML document won’t be problematic
from a rendering standpoint—but they will be displayed. HTML comments in CSS can
actually cause a CSS file to fail entirely.

No comments:

Post a Comment