I wrote a page this evening and found that many selectors are used, especially when multiple selectors exist on a tag.
So what will happen when all the five selectors are added to one tag? I tried it. We will share the following results with you.
<Html>
<Head>
<Style>
. C1 {
Background-color: red;
}
# D1 {
Background-color: blue;
}
Body, div {
Background-color: white;
}
Body # d1 {
Background-color: yellow;
}
Div {
Background-color: green;
}
</Style>
</Head>
<Body>
<Div id = '1' class = 'c1'> Hello </div>
</Body>
</Html>
The background is yellow, that is, the role is the body # d1 derivative selector. First, we need to understand a concept. In fact, each selector works. css is called a Cascading Style Sheet, in fact, I think it makes people better understand the stacked style sheet. As the name suggests, it is a layer-by-layer style sheet. That's right, it is actually like this. All selectors are executed, except that the derived selector is the final execution, so it overwrites the other selector. Here we will talk about priority or something, I think it is better to explain the order of execution.
Now that the derived selector is executed at the end, we can change the code and remove the derived selector to see the result.
The background is blue, so after removing the derived selector, the last one is the id selector.
The id selector is removed and the background is red. Therefore, after the id selector is removed, the last class selector is run.
Remove the class selector and the background is green. Here is a problem. If you replace the group selector and the label selector bit, the background will actually be white.
The following conclusions are as follows: the group selector and the tag selector are in front of each other, and the first two are in front of each other. Then, the class selector is executed, and the next is the id selector, the next step is the derived selector.
Some people may think that the test above is not complete yet. Yes, I can only say that you are very careful. The test above is not complete. You can change the selector order at will and come to the same conclusion as me.