How to specify the order of CSS classes?

前端 未结 3 1098
孤独总比滥情好
孤独总比滥情好 2020-12-02 08:40

I\'m a little confused about CSS and the class attribute. I always thought, the order in which I specify multiple classes in the attribute value has a meaning.

3条回答
  •  难免孤独
    2020-12-02 09:26

    The order in which the attributes are overwritten is not determined by the order the classes are defined in the class attribute, but instead where they appear in the CSS.

    .myClass1 {color:red;}
    .myClass2 {color:green;}
    Text goes here

    The text in the div will appear green, and not red; because .myClass2 is further down in the CSS definition than .myClass1. If I were to swap the ordering of the class names in the class attribute, nothing would change.

提交回复
热议问题