<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The result of the operation is:
Finally, we come to the conclusion that the same type of selector, CSS rules written in the last side of the effective!
Three-selector priority
CSS selectors combine a lot of complex selector rules, so we can't try to do it like a simple selector. Below we introduce a
A very useful method of judging the priority level.
Judge Priority: We agree that the ID selector has a weight of 100, a class selector weight of 10, and a label selector weight of 1. The right of a complex selector
Weight equals the sum of the weights of all selectors. In general, the more special The selector, the higher the priority (weight).
Let's take a look at two complex selector rules first:
The weight of the first selector is: 1+10+10+1=22
Div.test. Item span{
Background-color: #00FF00;
}
The weight of the second selector is: 100+1+1=102
#test Div span{
Background-color: #FF0000;
}
Judging from our agreed rules, it is clear that the second one is in force!
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The results of the operation are consistent with our theory!
Then we may have a question: the same weight, the selector function? From a series of theories and experiments we can draw this with the same kind
The priority of the type selector is similar, we can easily conclude that the same weights should be chosen in the final order of validity.
Four!important
Style Highest priority: none Depending on the priority, precede the last semicolon of a declaration in a style to make the style work .
Let's try it out:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
First run results we certainly know is red, then we!important behind the tag Selector, we will run the results to see?
/* The element selector renders a red */div{color: #0000FF!important;}
The result of the operation is:
About the priority of selectors I have learned this, CSS selector is over!!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
CSS Basic Learning 11: Selector priority