Skip to content
Advertisement

Vertical alignment of ::after pseudo elements

When I place svg image next to text, with vertical-align: middle;, then it aligns pretty nicely. However, if I use svg in the ::after pseudo-element, then the results are not as expected.

Before clicking on text elements

Furthermore, when I click on text to remove its content, then remaining svg element still keeps its unaligned position:

After clicking on text elements

Here is the code:

JavaScript
JavaScript
JavaScript

How to make this work, what has to be adjusted, and why? Why are not ⁣::after pseudo-elements aligned automatically with their “parents”?

Advertisement

Answer

It can be solved giving vertical-align: text-bottom; height: 46px; display: inline-block; to the after pseudo-elements:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement