Three characteristics of CSS: inheritance, cascading, priority

Three characteristics of CSS:

1. Inheritance

The internal tags contained in a page inherit the style of external tags. (Official explanation: The child element inherits the style of the parent element.) For example, the inheritable font-* (font family attribute), p, text-* (text series attribute) and so on. There are many uninheritable ones, including padding, border, margin, width, and height. Memorization suggestion: You just remember not to inherit, borders, margins, width and height description distance length etc. are not inheritable. You usually accumulate a lot, if you really can’t remember, try it, so you know if you can inherit it, and remember it when you write next time (ง •_•)ง

The p and span tags here inherit the color attributes of the external div tags. Width, height, margins, and borders are not inherited, which are non-inheritable elements!

2. Stackability

Cascading refers to the fact that there are multiple selectors or multiple styles in a selector acting on the same element, that is, the scope of action of the styles overlaps. (Official explanation)

As shown in the figure, the label selector, id selector and class selector all modify this text, and they all modify the color style. Since the id selector has the highest priority, this text is displayed in green. The cascade is related to priority, and the higher priority styles are displayed first.

Note: Different selectors or different styles modify the same attributes of the same element to be called cascade.

3. Priority

 !important> inline style> id selector> class selector> tag selector> default style It is whoever has the highest priority, which style is executed first!


Special Note:

The concept of css weight, and weight can be superimposed, you can understand it yourself. Anyway, I can’t remember it, it’s troublesome to calculate it, so let’s go with the feeling ♪ (^∇^*)

Reprinting without permission is prohibited! Remember to like and collect ヽ(✿゚▽゚)ノ

Guess you like

Origin blog.csdn.net/qq_44761243/article/details/108286401