Using multiple classes in one element and specificity

后端 未结 4 981
佛祖请我去吃肉
佛祖请我去吃肉 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:52

    A single class name carries the same weight. In such a scenario, the rule that is listed first will be overwritten by the second, and hence, the element will have margin-right: 0px;

    Here is a simple example using color instead of margin, because it's easier to visualize. The value specified in bar will be chosen by the browser.

提交回复
热议问题