The weighting relationship of CSS selectors

Source: Internet
Author: User

Tag: Class style effective width otherwise element selector wildcard property cannot

Keep in mind the weight relationship of CSS selectors and avoid the appearance of CSS styles not being effective in the page ~

inline ID class Elements
A B C D
Embedded 1 0 0 0
Id 0 1 0 0
class, attributes, Pseudo-classes 0 0 1 0
Elements, pseudo-elements 0 0 0 1
Wildcard characters * 0
!improtant (write in declaration, change the weight value) Highest
    • A set of values will only be 1 if the CSS is written into the style property, otherwise 0;
    • The B-group value is determined by the ID selector, how many ID selectors, and this array value is accumulated;
    • The value of the C group depends on the class selector, how many class selectors there are, and the values of this array are incremented;
    • The value of the D group is determined by the element selector, how many element selectors are available, and the accumulation of the array values.

Summarize:

    • weights are not rounded;
    • The embedded weight level is the highest, the inline is not entitled to re-relations, only the order of precedence;
    • Weights are at the same time, before being overwritten.

Weighting relationships for CSS selectors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.