Is it possible to reset all inherited CSS propeties?

后端 未结 4 924
一个人的身影
一个人的身影 2021-01-19 05:28

How do you reset ALL inherited properties for a class in a CSS file? I need to be able to set new properties on elements without pre-defined properties having an effect on i

4条回答
  •  猫巷女王i
    2021-01-19 06:06

    A class can't inherit properties. Inheritance is done through the DOM tree from the parent element. This will only happen if the default style for an element is to inherit, or if you have explicitly said some-property: inherit;.

    If you are asking how to stop rules from CSS rulesets that have selectors which match a given element from applying, then you can use the initial value. Note that:

    • It is from a working draft specification, so browser support may be weak to non-existent (I haven't see any documentation or performed any tests on support levels for it)
    • You still need to use a more specific selector (or some other method to win the cascade) for it to override any other styles.

    You'd probably be best off rewriting your stylesheet to be less broad in the elements it affects in the first place though. That approach will certainly have the best browser support.

提交回复
热议问题