CSS Deprecate single class when there are 2 classes

前端 未结 2 1776
旧巷少年郎
旧巷少年郎 2021-01-23 22:02

There is a div, and it has 2 class names.

like -

What I want is that if there are .A.B {}, the it will deprec

2条回答
  •  日久生厌
    2021-01-23 22:46

    In css whatever comes last takes precedence - that is why it is called a cascading style sheet. The exceptions to this are if the !important flag is used or if the previous selector is more specific than the latter. In your case .A.B{} is more specific and so it will automatically override any of the same attributes in .A{} and .B{}. If you want an attribute in .B{} to override an attribute in .B{} or vice versa you just need to make sure it comes last.

提交回复
热议问题