Is it possible to override the display property with its default value? For example if I have set it to none in one style, and I want to override it in a different with its default.
Or is the only way to find out what the default of that element is and then set it to that? Would like to not have to know if the element is usually block, inline or whichever…
A browser’s default styles are defined in its user agent stylesheet, the sources of which you can find here. Unfortunately, the Cascading and Inheritance level 3 spec does not appear to propose a way to reset a style property to its browser default. However there are plans to reintroduce a keyword for this in Cascading and Inheritance level 4 — the working group simply hasn’t settled on a name for this keyword yet (the link currently says
revert, but it is not final). Information about browser support forrevertcan be found on caniuse.com.While the level 3 spec does introduce an
initialkeyword, setting a property to its initial value resets it to its default value as defined by CSS, not as defined by the browser. The initial value ofdisplayisinline; this is specified here. Theinitialkeyword refers to that value, not the browser default. The spec itself makes this note under theallproperty:So I guess the only way right now using pure CSS is to look up the browser default value and set it manually to that:
(An alternative to the above would be
div.foo:not(.bar) { display: inline-block; }, but that involves modifying the original selector rather than an override.)