Type Selectors


The simplest kind of selector in CSS is the name of an element type. Using this kind of selector, which is called a type selector, you apply the declaration to every instance of the element type. For example, the selector of the following simple rule is H1, so the rule affects all H1 elements in a document:

 H1 { color: red } 

We used type selectors in Chapter 2, "CSS."

If you find yourself writing several style rules that are the same except for the selector, for example:

 H1 { color: red } H2 { color: red } H3 { color: red } 

You can write this more briefly by grouping the selectors in a comma-separated list:

 H1, H2, H3 { color: red } 

It is a matter of taste whether you want to use this grouping mechanism or not.

When selecting HTML elements, type selectors are case-insensitive. Therefore, the following four rules are equivalent:

 BLOCKQUOTE { margin-left: 2em } BlockQuote { margin-left: 2em } blockquote { margin-left: 2em } BLockQUoTE { margin-left: 2em } 

(For now, don't worry about the margin declarations; margins are explained in Chapter 8, "Space Around Boxes.")



Cascading Style Sheets(c) Designing for the Web
Cascading Style Sheets: Designing for the Web (3rd Edition)
ISBN: 0321193121
EAN: 2147483647
Year: 2003
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net