does the order of styles matter?

前端 未结 5 1389
不知归路
不知归路 2021-01-31 16:27

below is my markup. when i move the mouse over the hyperlinks they get underlined and turn red. but if i swap the order of the last two rules, the hyperlinks still get underline

5条回答
  •  孤城傲影
    2021-01-31 16:56

    If the rules are equal in specificity (in this case they are), individual rules get overridden in the order they're defined in the CSS, so in your example red wins because it comes later in the CSS definitions. The same rule applies in other cases as well, for example:

    Which of these wins?

    .green { color: green; }
    .red { color: red; }
    

    .red wins here, it doesn't matter the order in the class attribute, all that matters is the order the styles are defined in the CSS itself.

提交回复
热议问题