Looking at this demo, you will see that all browsers, except Opera, position the icon on the middle line of letter ‘A’, but Opera positions it slightly higher and over the line. The difference is not much noticeable here, but in some other cases it is.
What may be the reason for this behavior, and how may it be fixed?
Explanation
It seems that, although Opera is currently handling fine with either
inline-blockvertical alignment orline-heightdefinitions for pseudo elements (see reference tests for the former and the later to compare the rendering across UAs), the differentiation lies within the sizing definitions of replaced elements;As can be seen by examining a striped down demo on different browsers, solely having a replaced element (generated be the pseudo element’s
contentURL value) affects the layout such as the replaced element’s dimensions are added to the containing elements’ (in Opera). This results in the bizarre side effect you’re witnessing as, for now, the spec leaves it for the UA’s interpretation to decide how to treat those dimensions:Suggested Solution
Sidestep the issue to avoid tackling undefined behaviors, and use a more standard method of positioning pseudo elements; utilize absolute positioning:
CSS
Live Demo
References
:beforeand:afterpseudo elements on W3C.vertical-alignon Mozilla Developer Network.displayon Mozilla Developer Network.Further Reading