An important detail in understanding and applying Cascading Style Sheets is the cascading aspect of its name. That is, how does it handle multiple rules for the same element? This week, I will introduce the characteristics of CSS in detail and give examples.
priority
CSS properties have greater priority than HTML properties. You can use HTML attributes in browsers without CSS support, but adding CSS support to the browser will have no effect. When using CSS, it's important to have a deep understanding of the origin of a CSS rule.
source
When considering the application of CSS rules, there are usually two aspects. The first is the reader, which corresponds to the user viewing the web application through their preferred browser. The second aspect is the author, the actual web developer who developed the web application.
Reader preferences are handled by the user, that is, they can develop their own style sheets and then distribute them via browser settings. For example, Internet browser IE 6 users can specify a user style sheet via the Tools | Internet Options | Access menu so that they can use their own style sheet. Web developers develop their own CSS to specify rules and apply them in web pages. At the same time, browsers often have built-in rules.
cascade
The cascading aspect in the acronym CSS refers to the process of merging and overwriting rules between different sources. When multiple style sheets are used simultaneously, the selectors defined by each style sheet compete with each other for control. The following list specifies the order in which conflicts between style sheet selectors are resolved, with the first item being the most important.
Importance: Is the selector designated as important?
Rule source: Where are the rules defined?
Properties: What are the properties of the rule?
Sequence: What is defined last?