Inheritance: The so-called CSS style inheritance is the rule statement for child elements to apply to parent elements. (Due to this feature, CSS attributes can be divided into inheritable attributes and non-inheritable attributes.)
Inheritable attributes: Attributes whose attribute values can be inherited from parent elements to child elements are called inheritable attributes.
What properties are inheritable?
text-indent, text-align, word-spacing, letter-spacing, text-transform, text-decoration, direction, white-space
font, font-family, font-size, font-style, font-variant, font-weight
list-style, list-style-image, list-style-position, list-style-type
Note: Special explanation here: font-size Attributes (inheritance is special)
Unlike the exact value that is inherited, font-size inherits the calculated value.
For example:
<!DOCTYPE html>
<html lang=“utf8”>
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<body style="font-size:85%">
body字体大小
<h1 style="font-size:200%">h1字体大小</h1>
<h2 style="font-size:150%">h2字体大小</h2>
<p>p字体大小<em>em字体大小</em></p>
</body>
</html>
元素 | 值 | 计算值 |
default font-size | 16px | |
85% | 16px × 85% = 13.6px | |
200% | 13.6px × 200% = 27.2px | |
150% | 13.6px × 150% = 20.4px | |
unspecified | 13.6px | |
unspecified | 13.6px |
That is: unless the font-size value is reassigned, it will continue according to the last size value. For example, in the picture above, the body font is set to the default font (usually 16px=1em) 85% (13.6px), then the following fonts are all 13.6px. Instead of continuing to inherit 85%, let 13.6 be multiplied by 85% again.
Cascading: The so-called CSS style cascading is the process in which DOM elements apply rules in the style sheet to override inherited styles.