2018.2

Table Of Contents
Using a more specific CSS rule
By default, many CSS properties of an HTML element also apply to the elements inside that
element. For example, a CSS rule that specifies a certain font-type for a box also applies to
paragraphs in that box. In this example the box is the 'parent' element and the paragraphs are
the 'child' elements that inherit the font-type property of the box.
Note
Although the background color property seems to be inherited, it isn't. Most elements are
transparent; therefore the background color of the parent element shines through.
To replace inherited style properties, you need to add a more specific CSS rule for that (type of)
element. In case of a conflict between a general rule and a more specific rule, the more specific
rule will be applied.
The following diagram shows the order of specificity.
Rules for HTML elements (p, table, li etc.) are general rules. Rules for classes, pseudo classes,
and elements with a certain attribute (.class, :hover, [target]) are more specific. Rules for
elements with a certain ID are even more specific. The most specific are inline styles.
Example
Assuming that a table has the CSS property "color: red" (which colors text in the cells red), a
more specific rule for cells in that table could be, for example:
l A rule for the text color of all table cells (td elements), for example: td { color:
green; }.
Page 656