Getting Started with CSS (2) Inheritance and cascade of--CSS

Source: Internet
Author: User
1 Inheritance

There are some attributes, when set for themselves, their descendants are inherited, this is inheritance.

Which attributes can inherit.

The beginning of a color, text-, line-, and font-.

These types of text can be inherited, and all of the boxes, positioned, and layout properties cannot be inherited. If you set the body to:

1 body{

2 Color:gray;

3 font-size:14px; }

, the other elements in the body will also have these styles

<body>
<div>
<p> I am a paragraph </p>
<p> I am a paragraph </p>
<p> I am a paragraph </p>
</div>
</body>
2 cascade Sex

Cascade: CSS is the ability to handle conflicts. All weights are calculated without any compatibility issues.

Number of IDs, number of classes, number of labels

The number of IDs is the same as the ID, in turn.

If the weight is the same, then the occurrence of the following shall prevail:

#box1. hezi2 p{   //1,1,1------So for this
             color:red;
        }
        div div #box3 p{  //1,0,3
       & nbsp;    color:green;
        }
        div.hezi1 div.hezi2 div.hezi3 p{ //0,3,3
             color:blue;
        }

<div class= "Hezi1" id= "Box1" >
<div class= "Hezi2" id= "Box2" >
<div class= "Hezi3" id= "Box3" >
<p> Guess what color I am. </p>
</div>
</div>
</div>

If you can't select an element directly, the weight is 0 by inheriting the effect.

#hezi1 #hezi2 #hezi3 {
            color:red
        }
        div.box div.box div.box{
    & nbsp;       color:blue;
        }
        p{
            color: Green
        }

<div class= "box" id= "Hezi1" >
<div class= "box" id= "Hezi2" >
<div class= "box" id= "Hezi3" >
<p class= "pp" > Guess what color I am </p>
</div>
</div>
</div>

If everyone is 0, then there is a near principle: who describes the near, listen to WHO. #hezi3 {
Color:blue;
}
#hezi1 #hezi2 {
color:red;
}

<div class= "box" id= "Hezi1" >
<div class= "box" id= "Hezi2" >
<div class= "box" id= "Hezi3" >//Near
<p class= "pp" > Guess what color I am </p>
</div>
</div>
</div>


The same label, with multiple class names, conflicts:

<p class= "spec1 spec2" > What color I am. </p> <p class= " spec2 spec1" > What color I am. </p>

1. spec2{

2 Color:blue;

3}

4. spec1{//Red. Because red in CSS is written in the back. Behind the work

5 color:red;

6} </style>


Big summary of weight problem:

1) First See if there is no selection, if selected, then (ID number, class number, number of tags) to take into account the weight. Who listens to the big one. If all the same, after listening to write the subject.

2 if not selected, then the weight is 0. If everyone is 0, the nearest principle.


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.