How do I get my @import stylesheet to override the main stylesheet?

后端 未结 5 907
独厮守ぢ
独厮守ぢ 2021-02-05 18:20

I imported another stylesheet using @import in the main style sheet file. I would like the changes I have made in the @import stylesheet to override th

5条回答
  •  醉话见心
    2021-02-05 19:03

    If your second stylesheet uses the same selectors, then it should override the first without any problem.

    CSS has a very strict order of precedence for determining which one should be used, but if all else is equal and two styles have exactly the same precedence level, then it will use the one which was specified last. This allows you to override a style simply by repeating the same selector later on.

    The only exception to this is if the first style was specified as !important. In this case, it is much harder to override it. Even specifying another style as !important may not always work (I've seen cases where it worked in some browsers but not others).

    So if the previous stylesheet used !important then you may have problems overriding it. But if not, it should be fairly simple.

提交回复
热议问题