I have an icon within a div
, positioned vertically using absolute positioning. The div
is 39px tall, and the icon is 10px tall:
I want this icon vertically centered within the div
. My inspector (on Chrome) says that the icon is 14.5px away from the top:
which would mean the icon should be perfectly, vertically centered within the div. However, it does not look that way. So I measured it. The div
is indeed 39px tall and the icon is 10px tall, however... my eyeballs were correct about the image not being centered: the space above the icon is 16px, and the space below is 13px:
Why is the space above the icon not 14.5px like Chrome says it is and like my code says it will be? Where is the disconnect?
P.S. - I can understand 15px spacing on top and 14px spacing below due to rounding issues, but having a difference of 1.5px gets rid of that theory.
P.P.S - here is an example that more or less reproduces the issue: https://jsfiddle.net/0shzub2t/
P.P.P.S - and here is an example that is a deviation from my code for easier visualization: I think it shows the issue because in the example, I should have the top edge of the image right on the bottom edge of the div but the image is several pixels higher than it should be... https://jsfiddle.net/0shzub2t/1/