In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "the calculation method of CSS priority algorithm". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
About CSS specificity
CSS specificity feature or called extraordinary, it is a measure of CSS value priority of a standard, since as a standard, there is a set of relevant determination provisions and calculation methods, specificity with a four-digit string (CSS2 is three digits) to represent, more like four levels, values from left to right, the left side of the maximum, one level greater than one level, there is no binary between digits, levels can not be surpassed.
If multiple selectors are applied to the same element, the one with a high specification value will eventually get priority.
Selector Specification value list:
Rules:
1. The inline style priority specification value is 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 and 0, respectively.
Such as: sjweb
External definition refers to rules defined by or tag
2. The specification value declared by the benchmark is the highest.
In the case of the same 3.Specificity value, it is determined in the order in which it appears in the CSS code, and the CSS style of the latter is superior.
4. The style obtained by continuation does not have the calculation of specificity, it is lower than all other rules (such as those defined by the global selector *).
Algorithm:
When multiple selectors are encountered at the same time
The specification values obtained by selector are added bit by bit.
{there is no base between digits, for example: 0meme0re0jin0jin5 + 0memen0re0remen5 = 0meme0re0j0jr10 instead of 0mem0j0jol 1, 0}
The final calculated specificity is obtained.
Then the comparison trade-offs are compared bit by bit from left to right.
Case analysis:
1.div {font-size:12px;}
Analysis:
1 element {div}, and the specification value is 0re0re0re0re1.
2.body div p {color: green;}
Analysis:
There are 3 elements {body div p}, and the specification value is 0re0re0pl 0p3.
3.div .sjweb {font-size:12px;}
Analysis:
1 element {div}, and the specification value is 0re0re0re0re1.
1 class selector {.sjweb}, with a specification value of 0re0jj1,0
Finally: the Specialty value is 0, 0, 0, 1, 1, 1, 5, 5, 1, 1, 4, 5, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 4, 5, 4, 5, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
4.Div # sjweb {font-size:12px;}
Analysis:
1 element {div}, and the specification value is 0re0re0re0re1.
1 class selector {.sjweb}, the specification value is 0meme 0,0
Finally: the Specialty value is 0, 1, 0, 0, 1, 1, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 4, 5, 5, 5, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
5.html > body div [id= "totals"] ul li > p {color:red;}
Analysis:
The value of 6 elements {html body div ul li p} Specification is 0pm 0pm 0pm 6
1 attribute selector {[id= "totals"]} Specification value is 0memo 0memlori0
2 other selectors {> >} Specification values are 0pc0p0p0p0p0pl 0
Finally: the Specialty value is 0, 0, 0, 1, 6.
! important has the highest priority
This is the end of the content of "calculation method of CSS priority algorithm". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.