- CSS style inheritance
body,div,p{}
- HTML documents can be in the form of a variety of node trees, CSS cascading style sheet elements also have this correspondence
- <body> is the largest root node in the document, and all elements in the body are descendant elements of the body
- Analysis from the relationship of each element: there are several relationships between the elements:
E F descendant Relationships
E>f Parent-child relationship
E,f (E, can be any element type, can be cross-level)
E+f Neighboring relationships
Detailed Description:
An HTML document is a tree-like structure. There is a certain hierarchical relationship between the elements. This relationship is also reflected in CSS.
In CSS, the inner element inherits the style of the outer element;
The styles of multiple outer elements are eventually superimposed on the inner elements.
If the inner element individually specifies a property with the same name as the parent element, it will be replaced.
The <body> tag is all the styles in the topmost element,<body> and is inherited by its descendant elements.
?
What are the CSS properties that can be inherited?
Text styles, font styles, list styles have inheritance
Font-family,font-size,font-weight,font-style,color,,font
Text-indent,text-decoration,text-transform,line-height,text-align,
List-style-image,list-style-position,list-style-type,list-style
- Precedence of CSS Selectors
22 comparisons draw the following conclusions:
- Priority >class selector for row class styles
- Id>class
- The priority of the row class style >id
The above three conclusions draw:
Inline style >id style >class style
- 4,! Important> the priority of a row-class style
Conclusion:! important> inline style >id selector style >class selector style
?
CSS inheritance and precedence