CSS inheritance, layering, and specificity

Source: Internet
Author: User

1. Inheritance

(1) A style is applied to a particular HTML tag element and is applied to its descendants.

(2) But certain labels do not apply, such as border;

(3) Example: p{color:red;} Set the color

<p class= "First" >

<p id= "Second" >

The same effect.

2. particularity

(1) When the label matches more than one style, the browser according to the weights to determine which CSS style, the right value to use which.

(2) Example:

p{color:red;}. First{color:green;} <p class= "First" > Third grade, I was a little girl with a <span> timid </span>. </p>
The "timid" display is a green font.
(3) Rules:

3. Cascade

(1) 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.

(2) Example:

p{color:red;} P{color:green;} <p class= "First" > Third grade, I was a little girl with a <span> timid </span>. </p>
(3) Set the style level consistent, the final text is green, and the back is covered by the previous.
4. Importance
(1) Set the maximum weights for some styles and use important to resolve them.
(2) Syntax: P{color:red!important;}
(3) Example:
P{color:red!important;} P{color:green;} <p class= "First" > Third grade, I was a little girl with a <span> timid </span>. </p>
(4) The original is green covered with red, now is red covered with green, because the red set the highest weight value.

CSS inheritance, layering, and specificity

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.