CSS Stacking order

Source: Internet
Author: User

Priority level:

1, add! The group of important rules enjoys the highest priority; will be all without! The rules of Important

For example: #id {border:6px solid black!important} above #id{border:6px solid black;}

2, the second level style property embedded rules are not easy to maintain this method is not recommended

3. Third level rule with one or more ID selectors

For example #id{border:9px solid red} has precedence higher than. ID{BORDER:9PX solid red;}

4. Fourth level priority grouping rules with one or more classes, attributes, or pseudo-class selectors

For example, CLASS{BORDER:9PX solid red} is higher than div{border:2px solid black;}

5, level fifth one or more element selector precedence rules

For example: div{border:10px solid red} above *{border:5px solid black;}

6, the sixth level refers to those rules that contain only wildcard selectors

For example: *{border:5px solid black;}

Note: If the rule belongs to the same selector group, such as the relevant two rules contain ID selectors, then their priority will be based on the type and number of selectors compared; that with more high priority then this selector level is high

(! Important >style> ID selector > class selector > Label/element selector > wildcard selector)

If the same number and level of selectors are present, the priority will be judged based on the location

Position Grouping Priority:

1. Top-Priority HTML Document header <style> elements

The <style> element overrides the rules introduced by the @import statement in the <style> element

2. @import imported styles in the <style> element override the style of the link element attachment

The 3.link style overrides the rules introduced by the link element in the style introduced by @import, which overrides the end-user attached style sheet

4, the link element introduced in the style of @import introduced in the end user attached style sheet rules

5. User-attached style sheet (note: The user-added @important style has the highest priority)

6. Default rules provided by the browser

CSS Stacking order

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.