CSS inheritance and precedence

Source: Internet
Author: User

    1. CSS style inheritance


    1. HTML documents can be in the form of a variety of node trees, CSS cascading style sheet elements also have this correspondence
    2. <body> is the largest root node in the document, and all elements in the body are descendant elements of the body
    3. Analysis from the relationship of each element: there are several relationships between the elements:

      E F descendant Relationships

      E>f Parent-child relationship

      E,f (E, can be any element type, can be cross-level)

      E+f Neighboring relationships

Detailed Description:

An HTML document is a tree-like structure. There is a certain hierarchical relationship between the elements. This relationship is also reflected in CSS.

In CSS, the inner element inherits the style of the outer element;

The styles of multiple outer elements are eventually superimposed on the inner elements.

If the inner element individually specifies a property with the same name as the parent element, it will be replaced.

The <body> tag is all the styles in the topmost element,<body> and is inherited by its descendant elements.


What are the CSS properties that can be inherited?

Text styles, font styles, list styles have inheritance




    1. Precedence of CSS Selectors

      22 comparisons draw the following conclusions:

    • Priority >class selector for row class styles
    • Id>class
    • The priority of the row class style >id

The above three conclusions draw:

Inline style >id style >class style

    • 4,! Important> the priority of a row-class style

Conclusion:! important> inline style >id selector style >class selector style


CSS inheritance and precedence

Related Article

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.