XML technologies / CSS / CSS Cookbook / General topics / Comments in CSS code
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
You want to use comments to structure your CSS code and make it more readable.
Solution
Use the characters /* and */ to insert comments anywhere in your code:
/* Dies ist ein Kommentar */
a {
text-decoration: none;
}
/* Und dies ebenfalls */
h1, h2 {
font-size: 100%;
color: #666666;
}Discussion
One day, you may look at a stylesheet you wrote a long time ago and no longer remember why you took certain steps. Comments help explain and organize your code so that it remains understandable later. They also help people who did not write the code understand what was intended. Anything between /* and */ is ignored by the browser.
If you divide your code into sections, comments help distinguish them (header, footer, navigation, subnavigation, and so on). Comments can also make testing your pages much easier. Sometimes you are unsure whether a rule is correct or what effect it has. Simply enclose the rule in comment delimiters to disable it:
/*
a {
text-decoration: none;
}
*/The rule no longer affects the page’s appearance because the property text-decoration has been commented out. Unless other rules apply to the tag a, links will be underlined again until you remove the comment delimiters.
See also
The CSS 2.1 specification on comments.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln