HTML and CSS Reference
In-Depth Information
CSS Comments
Every programming language lets you add notes and other hints that help you understand
what's going on. Not all CSS is as understandable at first glance as, say, something like
font-size: 20px , so some sections of code can benefit from adding notes or other hints
in their vicinity. We introduced the syntax for CSS comments in Chapter 2 . You might re-
member this bit of code from our clearfix:
.cf {
*zoom: 1; /* for IE6 and IE7 */
The comment in this line of code is the part that says “for IE6 and IE7,” and is identifiable
as such by the preceding backslash followed by an asterisk, and the asterisk and backslash at
the end.
We can add as many of these to our stylesheet as we like, and it's good practice to use CSS
comments to help identify parts of any stylesheet that might be difficult to understand from
a cursory glance. By using CSS comments to make our stylesheets more readable, the CSS
will be easier to maintain in the future.
ACSScomment canspanmultiple linesifrequired.Everything that'sinbetween theopening
and closing comment characters will be ignored by the browser, and so will the comment
characters themselves. So often you'll see something like this in a CSS file:
These are the styles for
the header section
Notice that, in this example, not only have I included the opening and closing asterisk and
backslash characters, but I've also added some extra asterisk characters spanning multiple
lines. This makes the comment easy to find when scrolling through the CSS file. Add section
headings like this in CSS to help organize it into readable, related chunks of code.
Search WWH ::

Custom Search