Using multiple classes in one element and specificity

后端 未结 4 978
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-12 12:41

    In addition, more "specific" class will override a more generic one:

    HTML:

    Hello World!

    With the following CSS:

    .foo .bar { margin-left:25px }
    .bar { margin-left:0px }
    

    Notice how the inner div still has 25px margin to the left?

    Also, read up on "!important" argument after providing the value:

    .bar { margin-left:0px!important }
    

    Check out

提交回复
热议问题