Overriding CSS properties that don't have default values

前端 未结 2 1086
暗喜
暗喜 2021-02-08 11:07

Is it possible in CSS to override a property if that property doesn\'t have a default value?

For example, say your primary stylesheet defines a border for a particular

2条回答
  •  无人及你
    2021-02-08 11:39

    If I'm reading your question correctly, do you want to, in one stylesheet, "erase" a declaration that you have in another stylesheet, such that the property will compute to the default value?

    There's currently no way to reset it to whatever the value a browser uses as the default for a given element. The closest you can get is with the CSS3 initial keyword, which resets a property to its initial/default value according to the spec rather than according to how a browser defines it:

    #element {
      left: initial;
      right: 0;
      top: 0;
    }
    

    There's not much browser support for it besides in Safari/Chrome and Firefox (as -moz-initial), so your next best alternative is to look up the initial value and hardcode it. For the left property, it's auto (and I believe it's this value for any element in all browsers anyway), so:

    #element {
      left: auto;
      right: 0;
      top: 0;
    }
    

提交回复
热议问题