I have the following examples to demo a font trying to stay in the middle of a div, using both normal text manipulation and flex display manipulation. Both seem to place the font in the middle, however, when your browser is not maximised and you try to change the width of the browser, both fonts wiggle within the div (you have to do this slowly to see the effect).
I made an animated GIF to show what I am talking about:
As the font size is fixed and the width and height of the enclosing div are also fixed, changing the width of the browser should not affect the position of the font within the enclosing div.
How do you make the font absolutely stable in the middle (has to be a font, not an image, can be SVG though if that is necessary), hence not wiggling when browser width changes?
div {
display: flex;
justify-content: center;
margin: 10px;
}
span.text {
height: 30px;
width: 30px;
line-height: 30px;
text-align: center;
font-size: 30px;
font-weight: bold;
color: white;
background: green;
}
span.flex {
height: 30px;
width: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
font-weight: bold;
color: white;
background: green;
}
<div>
<span class="text">+</span>
</div>
<div>
<span class="flex">+</span>
</div>