O'Reilly logo

HTML, XHTML, and CSS Bible, Fifth Edition by Steven M. Schafer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 26. Style Definitions

IN THIS CHAPTER

  • The Style Definition Format

  • Understanding Selectors

  • Understanding Style Inheritance

  • Using Pseudo-Classes

  • Pseudo-Elements

  • Shorthand Expressions

By this point in the book, you should recognize the power and versatility that styles can bring to your documents. You have seen how styles can make format changes easier and how they adhere to the content versus formatting separation. Now it's time to learn how to create styles—the syntax and methods used to define styles for your documents.

The Style Definition Format

CSS style definitions all follow the same basic format. A definition starts with a selector expression used to match elements within the documents(s), and is followed by one or more style properties and value sets. Roughly, this format approximates the following structure:

selector {
   property: value(s);
   property: value(s);
   ...
 }

The selector is an expression that can be used to match specific elements within HTML documents. Its simplest form is an element's name, such as h1, which would match all h1 elements. At its most complex, the selector expression can be used to match individual sub-elements of particular elements or to specify text to include before or after matched elements.

Note

Selectors are covered in depth within the next section of this chapter. Acceptable property values are covered in Chapter 27. Individual CSS properties are covered in topical chapters, Chapter 29 through Chapter 37.

The property component of a style rule specifies ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required