When you apply two or more CSS rules to the same text, the rules might conflict and produce unexpected results. Browsers apply CSS rules as follows:
class
attribute) override attributes from HTML tag styles.In the example that follows, the style defined for h1
might specify the font, size, and color for all h1
paragraphs, but the custom CSS rule .Blue
applied to this paragraph overrides the color setting in the h1
style. The second custom CSS rule .Red
overrides .Blue
because it is inside the .Blue
style.
<h1><span class="Blue">This paragraph is controlled by the .Blue custom style and h1 HTML tag style.<span class="Red">Except this sentence is controlled by the .Red style.</span> Now we're back to the .Blue style.</span></h1>