CSS style cascading order
When multiple style sheets are used, the style sheets need to compete for control of specific selectors. In these cases, there are always style sheet rules that gain control. The following properties will determine the outcome of competing style sheets.
As mentioned before, both web page authors and readers have the ability to specify style sheets. When the two rules conflict, the web page creator's rules will override the readers' other rules of equal weight. The style sheets of web page creators and readers exceed the browser's built-in style sheets.
Web page authors should use ! important rules with caution, as they will override any ! important rules the user has. For example, a user may require large fonts or specific colors due to visual constraints, and such a user may declare certain style rules as ! important, because these styles are extremely important for users to read web pages. Any ! important rules will override the general rules, so it is recommended that web page authors use general rules to ensure that users with special style needs can read the web page.
Selector rules: Computed attributes are based on their attribute level. Style sheets can also override conflicting style sheets. A higher-attribute style will always override a lower-attribute style. This is just a statistics game that counts the specified number of selectors.
Count the number of ID attributes in the selector.
Count the number of CLASS attributes in the selector.
HTML tagname format in statistics selector.
Finally, write the three numbers in the correct order without spaces or commas to get a three-digit number. (Note that you need to convert the number to a larger number that ends with three digits.) The final list of numbers corresponding to the selector makes it easy to determine that the properties of the higher number override those of the lower number. The following is a list of selectors classified by characteristics: #id1 {xxx} /* a=1 b=0 c=0 ——> characteristics = 100 */ UL UL LI.red {xxx} /* a=0 b =1 c=3 ——> Characteristics = 013 */ LI.red {xxx} /* a=0 b=1 c=1 ——> Characteristics = 011 */ LI {xxx} /* a=0 b=0 c=1 ——> Feature = 001 */The order of features is for convenience. When two rules have the same weight, the later one is taken.
When multiple style sheets are used, the style sheets need to compete for control of specific selectors. In these cases, there are always style sheet rules that gain control. The following properties will determine the outcome of competing style sheets.
As mentioned before, both web page authors and readers have the ability to specify style sheets. When the two rules conflict, the web page creator's rules will override the readers' other rules of equal weight. The style sheets of web page creators and readers exceed the browser's built-in style sheets.
Web page authors should use ! important rules with caution, as they will override any ! important rules the user has. For example, a user may require large fonts or specific colors due to visual constraints, and such a user may declare certain style rules as ! important, because these styles are extremely important for users to read web pages. Any ! important rules will override the general rules, so it is recommended that web page authors use general rules to ensure that users with special style needs can read the web page.
Selector rules: Computed attributes are based on their attribute level. Style sheets can also override conflicting style sheets. A higher-attribute style will always override a lower-attribute style. This is just a statistics game that counts the specified number of selectors.
Count the number of ID attributes in the selector.
Count the number of CLASS attributes in the selector.
HTML tagname format in statistics selector.
Finally, write the three numbers in the correct order without spaces or commas to get a three-digit number. (Note that you need to convert the number to a larger number that ends with three digits.) The final list of numbers corresponding to the selector makes it easy to determine that the properties of the higher number override those of the lower number. The following is a list of selectors classified by characteristics: #id1 {xxx} /* a=1 b=0 c=0 ——> characteristics = 100 */ UL UL LI.red {xxx} /* a=0 b =1 c=3 ——> Characteristics = 013 */ LI.red {xxx} /* a=0 b=1 c=1 ——> Characteristics = 011 */ LI {xxx} /* a=0 b=0 c=1 ——> Feature = 001 */The order of features is for convenience. When two rules have the same weight, the later one is taken.