Consider this HTML/CSS scenario:
p { content:'x'; }
p:before, p:after { content:inherit; }
<p></p>
In Firefox, 'xx' will be displayed. In Chrome and in IE nothing is displayed.
In assessing what I think should happen, I've taken into account the following snippets from the CSS 2.1 spec:
12.1 The :before and :after pseudo-elements
The :before and :after pseudo-elements inherit any inheritable properties from the element in the document tree to which they are attached.
So, in general, inheriting a property into a :before and :after pseudo-elements from their containing element should work (and it does work for other properties).
'content' Value: normal | none | [ | | | attr() | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
So "inherit" is a valid value for the content property
Computed value: On elements, always computes to 'normal'. On :before and :after, if 'normal' is specified, computes to 'none'. Otherwise, for URI values, the absolute URI; for attr() values, the resulting string; for other keywords, as specified.
The important thing here is that this discusses the computed value of the property. Also note that the computed value for elements like the <p>
element in the example should be normal
Applies to: :before and :after pseudo-elements
This part lists the elements to which the property applies. All elements are considered to have all properties, but some properties have no rendering effect on some types of elements. ...
So "applies to" is a rendering rule, and does not determine whether the property is meaningful for the element, because all CSS properties are always meaningful.
Each property may also have a cascaded value of 'inherit', which means that, for a given element, the property takes the same specified value as the property for the element's parent. The 'inherit' value can be used to enforce inheritance of values, and it can also be used on properties that are not normally inherited.
Note that it is the specified value that is inherited, not the computed value. For the <p>
element of the example, the specified value of the content property is "x".
Now, in IE's DOM inspector, the computed value of the content for the p element is normal
, taken from a specified value of "x". This seems correct to the spec, but the specified value is not being inherited by the pseudo-elements.
In Chrome's DOM inspector, the computed value of the content for the p element is not shown at all! Why Chrome should omit any property is unknown to me. Calling window.getComputedStyle(el).content on the element returns "x". As with Firefox, the seems to be incorrect to the spec.
In Firefox's DOM inspector, the computed value of content for the p element is "x". This seems incorrect according to the spec, which says that the computed value should be normal
. However, the specified value is being inherited by the pseudo-elements.
So I conclude that all three of Firefox, IE, and Chrome's behaviour are in some way bugged, but that Firefox is correct in displaying "xx" for the example scenario.
Have I missed anything relevant?