How are the points in CSS specificity calculated

后端 未结 7 1690
萌比男神i
萌比男神i 2020-11-21 05:18

Researching specificity I stumbled upon this blog - http://www.htmldog.com/guides/cssadvanced/specificity/

It states that specificity is a point-scoring system for

7条回答
  •  盖世英雄少女心
    2020-11-21 06:05

    I would say that:

    Element < Class < ID
    

    I think they only stack into depending what you get if it is multiple of the same. So a Class will always overide the element and ID always over the Class but if it is down to which of 4 elements where 3 is to blue and 1 is to red it will be blue.

    For Example:

    .a .b .c .d .e .f .g .h .i .j .k .l
    {
    color: red;
    }
    
     .m .n .o
    {
    color blue;
    }
    

    Should turn out red.

    See Example http://jsfiddle.net/RWFWq/

    "if 5things say red and 3 say blue well Ima go red"

提交回复
热议问题