For a responsive website, I am trying to center a text and scale its font-size using SVG so that I don't need to do any calculations with JavaScript.
My first problem is that I tried using x="50%"
and y="50%"
with text-anchor="middle"
and alignment-baseline="central"
but while this works in Chrome, in IE, Edge and Firefox the text is not vertically centered, but its baseline is so that the text itself is slightly too high. How can I center the text vertically in those browsers too without having a fixed height?
My second problem is scaling. What I found so far on the Internet is using lengthAdjust="spacingAndGlyphs"
but that gives weird results with the text appearing stretched. How can I scale everything just like an image would be scaled?
Here is my starting pen: https://codepen.io/smares/pen/QMVPvN
I also read about viewBox
, but I don't fully understand how to use that given I have no container with fixed sizes.
I have to use inline SVG because the text is actually generated by Vue.