According to the MDN docs for revert
, it respects inheritance. So, in theory, if I have this HTML:
<div class="container">
<h1 class="header">there</h1>
</div>
and this CSS:
.container {
font-weight: normal;
}
.header {
font-weight: revert;
}
the weight of the text should be normal. In theory, revert
should first look to its parent (font-weight is an inherited property). Yet, this does not happen. Why?
This is especially odd, considering the fact that I’m applying "revert" directly to the element (so the theory about browser styles overwriting the element styles don’t quite hold in this case).
2
Answers
Revert resets the property to the value it would have from browser defaults or user-defined styles.
It does not simply fall back to the nearest inherited value in the cascade.
Use inherit if you want to inherit the parent’s value directly.
revert
may respect inheritance, but it does not substitute forinherit
:As Kosh commented, usually the user agent sets a
font-weight
on<h1>
.For
.header1
, we override the user agent styles by explicitly inheriting font weight.For
.header2
, we forget any previous styles for font weight that were applied within the current cascade origin, which in this case is our unlayered author styles. Since we have no existing styles for the element from our author styles this essentially does nothing in this instance.Even though
font-weight
is an inherited property (e.g. a div would inherit font weight from.container
) – since the element is anh1
, the browser’s default styles assign a font weight which takes precedence in the cascade over inheritance.