Grouping and Shorthand Properties

The style definitions in the preceding code listings have been written out in their full form. To ease authoring tasks and reduce the size of style sheets, the CSS1 specification supports a feature called grouping, which allows a set of comma-separated selectors to be given the same styles. For example, you might write these three separate style definitions:

 H1 {font-size: 16pt; font-weight: bold; color: red} H2 {font-size: 16pt; font-weight: bold; color: red} H3 {font-size: 16pt; font-weight: bold; color: red} 

By using grouping, the code can be shortened to the following:

 H1, H2, H3 {font-size: 16pt; font-weight: bold; color: red} 

You can also use shorthand properties (also known as composite properties) to "group" certain style attributes. Using shorthand properties allows you to set multiple similar attributes simultaneously. For example, consider a style definition that includes the font-weight, font-size, and font-family attributes:

 H1 {font-weight: bold; font-size: 16pt; font-family: Verdana} 

The same formatting can be accomplished with the font shorthand property as follows:

 H1 {font: bold 16pt Verdana} 

Within a shorthand property, the individual attributes must be listed in a specific order. In other words, the slightly different code

 H1 {font: 16pt bold Verdana} 

will not yield the results you might expect because the font-size and font-weight attributes are reversed.

A variety of other shorthand properties exist, such as border, margin, and padding. You can find more information about the use of shorthand properties in CSS, including the specified order of attributes, in Chapters 12 and 13, as well as on the SBN Workshop Web site and on the CD that accompanies this book. On the CD, see Workshop (References); DHTML, HTML & CSS; CSS; CSS Attributes Reference. To get to the online version, visit the MSDN Online Resource page at msdn.microsoft.com/resources/schurmandhtml.htm , or open the file named MSDN_OL.htm on the companion CD, and choose CSS Attributes.



Dynamic HTML in Action
Dynamic HTML in Action
ISBN: 0735605637
EAN: 2147483647
Year: 1999
Pages: 128

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