Beginning HTML5 and CSS3 For Dummies
Book image
Explore Book Buy On Amazon

Understanding the rules of inheritance in CSS3 helps you create interesting sites that require a minimum of maintenance. By following these rules, when maintenance is required, you normally have to make just one change, rather than changing hundreds of items individually. It pays to experiment, though, so you can understand the full effects of inheritance and the effects of using multiple styles together.

  1. Create a new HTML5 file with your text editor.

    Your editor may not support HTML5 files. Any text file will do.

  2. Type the following code for the HTML page.

    
     Inheritance Example
     
    
    
     

    An Example of CSS Inheritance

    A paragraph outside a <div>.

    A paragraph inside a container.

    This page contains a number of inline styles, which always have the highest inheritance precedence. For example, the provides a font-family of monospace for the

    tag part of the sentence. You could accomplish the same thing by assigning the a class attribute for code, but this example uses the inline style instead.

    The

    uses an inline style to set the text-align style to left. Because the default style sets the alignment to left, you won’t see any difference. However, if another style change modifies the text alignment, this style will take effect and prevent movement of this paragraph.

    The internal style modifications all appear within the

About This Article

This article can be found in the category: