Using multiple classes in one element and specificity

后端 未结 4 995
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-12 12:30

Just wondering when you use multiple classes on the one element such as class=\"foo bar\" and those classes are setup as below:

.foo {
    margin-ri         


        
4条回答
  •  故里飘歌
    2021-02-12 12:51

    It works based on precedence within the CSS. Therefore the item to occur most recently will override any previous styles.

    CASE 1

    .foo  { background : red; }
    .bar  { background : blue; }
    

    class = 'foo bar' would be blue in this instance.

    CASE 2

    .bar  { background : blue; }
    .foo  { background : red; } 
    

    class = 'foo bar' would be red in this instance.

    Working Example

提交回复
热议问题