CSS inheritance, stacking and particularity

Source: Internet
Author: User

1, some styles of inheriting CSS are inherited, so what is inheritance? Inheritance is a rule that allows a style to be applied not only to a particular HTML tag element, but also to its descendants.

Note, however, that there are some CSS styles that are not inherited. such as border:1px solid red;

2, special sometimes when we set different CSS style code for the same element, which CSS style is enabled by the element? The browser is based on the weights to determine which CSS style to use, which of the high weight of the use of that CSS style.

Weight rule: The weight value of the label is 1, and the weight of the class selector is the weight of the 10,id selector is 100.

For example:

/ * Weighted value is 1*/ / * Weighted value is 1+1=2*/ / * Weighted value is 10*/ / * Weighted value is 1+1+10=12*/ / * Weighted value is 100+10+1=111*/

Note: There is also a special weighted value-inheritance also has the right value but very low, some literature proposed it only 0.1, so it can be understood as the lowest weight of inheritance.

3, cascading is in the HTML file for the same element can have more than one CSS style exists, when the same weight of the style exists, according to the order of the CSS style to decide, in the back of the CSS style will be applied.

4, importance when we are doing the code of the Web page, some special cases need to have the highest weight for some style setting, we can use !important to solve it.

The following code:

p{color:red!important;} P{color:green;} <p class= "First" > Third grade, I was a little girl with a <span> timid </span>. </p>

The text in the p paragraph is then displayed in red.

Note:!important to be written in front of the semicolon

Style priority is: browser default Style < page maker Style < user-set style , but remember that the!important priority style is an exception and the weight is higher than the user's own set style.

CSS inheritance, stacking and particularity

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.