The cascade in CSS determines what rules get applied to our HTML. There are multiple factors used in this determination
Specificity
A CSS declaration that is more specific will take precedence over less specific ones.
Specificity is only taken into account when as a tiebreaker when an element has multiple conflicting declarations targeting it
Conflicting declarations
A rule consists of one or more declarations. Specificity applies to declarations.
Thus, even if some of a rule’s declarations are overridden in specificity by the declarations of another rule, its non-conflicting declarations can still apply
Inheritance refers to certain CSS properties that, when applied to an element, are inherited by that element’s descendants, even if we don’t explicitly write a rule for those descendants.
Typography inheritance
Typography based properties (color, font-size, font-family, etc.) are usually inherited, while most other properties aren’t.
The exception to this typography inheritance is when directly targeting an element, as this always beats inheritance:
Though the first rule that targets parent (ID selector) has higher specificity, the inheritance by the child div is overridden by the direct targeting of the declaration in the second rule. Thus the text color will be blue
Rule order
The final tie-breaker when every other factor has been taken into account and conflicting rules targeting an element still exist