Monday, September 13, 2010

The rules of CSS

Style sheets consist of a number of rules that define how various web page elements
should be displayed. Although sometimes bewildering to newcomers, CSS rules are simple
to break down. Each rule consists of a selector and a declaration. The selector begins a CSS
rule and specifies which part of the HTML document the rule will be applied to. The declaration
consists of a number of property/value pairs that set specific properties and
determine how the relevant element will look. In the following example, p is the selector
and everything thereafter is the declaration:
p {
color: blue;
}
As you probably know, p is the HTML tag for a paragraph. Therefore, if we attach this rule
to a web page (see the section “Adding styles to a web page” later on in this chapter for
how to do so), the declaration will be applied to any HTML marked up as a paragraph,
thereby setting the color of said paragraphs to blue.
CSS property names are not case sensitive, but it’s good to be consistent in web
design—it’s highly recommended to always use lowercase. Note, though, that
XML is case sensitive, so when using CSS with XHTML documents served with
the proper XHTML MIME type, everything must be consistent. Also, the W3
specifications recommend that CSS style sheets for XHTML should use lowercase
element and attribute names.
AN INTRODUCTION TO WEB DESIGN
11

No comments:

Post a Comment