css--Cascade

Source: Internet
Author: User

1. Cascading is a mechanism for resolving conflicts between CSS declarations.

CSS conflicts: Multiple identical maturity declarations, which are used for the same element will create a conflict.

2. Cascading process "1" comparison priority

Each declaration has a priority, and when a declaration conflicts, it retains a high priority, and the elimination priority is low.
The priority of a statement is related to his source and importance.
The source is generally divided into three parts: browser default style, author style, user style
The order of precedence from highest to lowest is: User style, author style, browser default style.
Importance: If a property value is followed by a "! Importent ", it represents an important statement, otherwise it is a general declaration.
Column:

p{color:red;}/*普通声明*/p{color:red importent;}/*重要声明*/
"2" Comparative particularity (specificity)

When the declaration of conflict, the specificity of the high will be retained, the special low will be eliminated.
The particularity of the declaration depends on the size of the actual scope of the rule, the smaller the applicable scope of the rule, the higher the particularity, the more the particularity.
Note:

*{声明块}/*通配符选择器,他的应用范围是整个页面*/html{声明块}/*这两个选择器时范围最大的选择器*/

Common style peculiarities from high to low rank:
1. Inline style
2.id selector
3. Class Selector
4. Element selector
5. Wildcard Selector

When "3" is more special, the essence is the specific value (value) of the comparative Declaration.

We assume that:
The inline style generates a value of (is the inline style generation 1 otherwise 0): a
The number of ID selectors generates a value of: b
The number of classes and pseudo-class selectors generates a value of: C
The number of elements and pseudo-element selectors generates a value of: D
Each declaration of a and A, B and B,c and c,d with the value of D, if obtained a maximum of a value, the maximum value corresponding to the declaration of the higher the specificity, if there is no maximum value is compared to the value of B, the comparison method is the same, and so on ... the HTML element will use the maximum value corresponding to the declaration.

css--Cascade

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.