Cascading and inheritance

The final style for an element can be specified in many different places, which can interact in a complex way. This complex interaction makes CSS powerful, but it can also make it confusing and difficult to debug.

Three main sources of style information form a cascade. They are:

  • The browser's default styles for the markup language.

  • Styles specified by a user who is reading the document.

  • The styles linked to the document by its author. These can be specified in three places:

    • In an external file: this tutorial primarily discusses this method of defining styles.

    • In a definition at the beginning of the document: use this method only for styles that are used only on that page.

    • On a specific element in the body of the document: this is the least maintainable method, but can be used for testing.

For styles in the cascade, author stylesheets have priority, then reader stylesheets, then the browser's defaults.For inherited styles, a child node's own style has priority over style inherited from its parent.

These are not the only priorities that apply.

CSS also provides a way for the reader to override the document author's style, by using the keyword !important.

你可能感兴趣的:(Cascading and inheritance)