vertical alignment of text element in SVG
Solution 1:
According to SVG spec, alignment-baseline
only applies to <tspan>
, <textPath>
, <tref>
and <altGlyph>
. My understanding is that it is used to offset those from the <text>
object above them. I think what you are looking for is dominant-baseline
.
Possible values of dominant-baseline
are:
auto | use-script | no-change | reset-size | ideographic | alphabetic | hanging | mathematical | central | middle | text-after-edge | text-before-edge | inherit
Check the W3C recommendation for the dominant-baseline property for more information about each possible value.
Solution 2:
The alignment-baseline
property is what you're looking for it can take the following values
auto | baseline | before-edge | text-before-edge |
middle | central | after-edge | text-after-edge |
ideographic | alphabetic | hanging | mathematical |
inherit
Description from w3c
This property specifies how an object is aligned with respect to its parent. This property specifies which baseline of this element is to be aligned with the corresponding baseline of the parent. For example, this allows alphabetic baselines in Roman text to stay aligned across font size changes. It defaults to the baseline with the same name as the computed value of the alignment-baseline property. That is, the position of "ideographic" alignment-point in the block-progression-direction is the position of the "ideographic" baseline in the baseline-table of the object being aligned.
W3C Source
Unfortunately, although this is the "correct" way of achieving what you're after it would appear Firefox have not implemented a lot of the presentation attributes for the SVG Text Module ('SVG in Firefox' MDN Documentation)