css 高度继承父类
When you set some properties on a selector in CSS, they are inherited by all the children of that selector.
在CSS中的选择器上设置某些属性时,该属性将由该选择器的所有子级继承。
I said some, because not all properties show this behaviour.
我说了一些 ,因为并非所有属性都显示此行为。
This happens because some properties make sense to be inherited. This helps us write CSS much more concisely, since we don’t have to explicitly set that property again on every single children.
发生这种情况是因为可以继承某些属性。 这有助于我们更加简洁地编写CSS,因为我们不必在每个子节点上都再次显式设置该属性。
Some other properties make more sense to not be inherited.
其他一些属性更有意义,那就是不被继承。
Think about fonts: you don’t need to apply the font-family
to every single tag of your page. You set the body
tag font, and every children inherits it, along with other properties.
考虑一下字体:您无需将font-family
应用于页面的每个标签。 设置body
标记字体,每个子代都会继承它,以及其他属性。
The background-color
property, on the other hand, makes little sense to be inherited.
另一方面, background-color
属性几乎没有意义。