untitled

(John Hannent) #1
Inheritance is useful because you don’t have to specify that <strong>, the
child of <p>, should also be colored green, or have other characteristics of
the parent element. Inheritance is obviously a time-saver with elements such
as lists that have many children. All the children turn green at once because
they inherit that color from their parent.

A few properties are not inherited, however, because it doesn’t make sense
in some cases. For example, you don’t want child elements to inherit the mar-
gins used by their parents. A main purpose of margins is to distinguish parent
text blocks from child blocks, so they should have different margins. Likewise,
borders, padding, and backgrounds are not inherited.

46 Part I: The ABCs of CSS

Free download pdf