It appears that a unicode emoji character overflows it's bounding box on a non-retina display, but it remains within the character bounds on a retina display. So how do I horizontally center an emoji in a div on both a retina and a non-retina display?
Non-Retina:
Retina:
This works on a retina screen, but is off a few px on a non-retina display:
<div style="text-align: center; width: 3rem; border: 1px solid red;">π</div>
Here is a CodePen to try things https://codepen.io/anon/pen/GmzoNP. You will need a retina and non-retina screen to observe the problem.
Here are some of my ideas that I tried. I have not had success with them yet but I think the last two are on the right track:
- Text-align center (it is text after all)
- width: 0, 50% left margin, transform: translateX(-50%)...
- Changing character width
- Using a monospace font
A little context about how others have solved this problem - Slack and Google both just use images of emojis. This is not ideal in my case because it increases bundle size and and requires some extra logic to handle copy/paste.