The reason why the icon isn’t centered is because of two things:
You are trying to resize the container (<i>) of the actual vector graphic instead of the actual graphic (::before inside <i>). This moves the graphic to the right whenever its container gets smaller.
Font awesome is using unicode characters to display icons. They are basically text. To resize the graphic itself you can do this (the 2em value is an example):
.add-img-button::before {
font-size: 2em;
}
You can use the transform: translate(-50%, -50%) option to move the anchor point of an element to its center and then position it using left: 50%, top: 50%.
I have a div which is a square and stays a square regardless of the device. I need to place a FontAwesome icon inside this square and I need the icon to stay centered in all screens. For some reason I’m not achieving this.
In desktop it looks good, you can see the icon in horizontally and vertically centered:
In mobile it looks like the image below, the icon is no longer centered:
I would like to achieve this without using media queries. Here’s my Codepen.