Section IV of CSS inheritance and cascading

I. inheritance

   1. Meaning: from the smallest elements of their own until the beginning of the package, can inherit some unique attributes.

   2. Range: 

       a. color, beginning with text-, beginning with line-, font- beginning, can be inherited.

       . B text style, can inherit; all about the box, positioning, can not inherit the layout.

   3. Example:

   

II. Laminating properties

   1. Background : When a plurality of simultaneously selecting a label related to a certain time, who styles to prevail, then involve lamination of the weight problem.

   2. Meaning : CSS is to resolve conflicts. (All weights calculated, there is no compatibility issues).

   3. weight calculation rules :

        A. First, check to see whether the label, if you select the label, then in accordance with (the number of id number> class class> tag number) to calculate the weights, large who listen to whom; If the weights are the same, whichever is later write.

        B. If not checked, then the weight is 0, take the principle of proximity, who nearly across the target label, who heard.

   4. classic five questions:

    Question 1:

        uploading.4e448015.gifDump failed to re-upload canceled

     Explanation: are selected, and this time compare the weight, the answer is red.

    Problem 2:

    

    Explanation: no check, a weight of 0; but the span tag closer description of the red, so the answer is red.

    Question 3:

    

    Explanation: The second and third did not check, a weight of 0; first selected, have the right heavy, so the answer is green.

    Question 4:

      

 

       Explanation: This split open, there are three selectors, and are selected, the second and third equally weighted, so after writing the main, the answer is green.

    Question 5:

       

   Explanation: As long as there is a glimmer of hope can select the target, we believe selected, as the first one of the first div selector who is, we do not need attention, more weight can be seen, the answer is blue

5. Weight-depth

  A. with a label carrying the name of more than one class, there is a conflict between the class name.

  

 

   B. !important标记

          (1).可以给1个属性提升权重,这个属性的权重就无穷大。

          (2).该标记提升的是一个属性,而不是一个选择器。

          (3).该标记无法提升继承的权重,该是0还是0。

          (4).该标记不影响就近原则。

          案例:

          1. <p id="para1" class="spec">文字</p>

    

uploading.4e448015.gif转存失败重新上传取消

           2. 

    

 

          3. 

           

 

    总结: !important标记,只有作用在一个选择器包含的属性上,且该选择器选中了目标,此时!important才会起作用,对应未选中的、继承的统统不起作用

发布了564 篇原创文章 · 获赞 52 · 访问量 8万+

Guess you like

Origin blog.csdn.net/sinolover/article/details/104330553