为了在SVG中垂直对齐文本,必须使用dominant-baseline
属性。 这已经在SO(Aligning text in SVG)上讨论过,并且是the specification的一部分。如何在IE9中垂直居中SVG文本
我的问题是与IE9显然does not support dominant-baseline
和一堆other things。
对IE9中的如何近似dominant-baseline: central
有什么建议吗?
这是一个在FF和Chrome中可用的示例。它在IE9,Opera 11中不起作用.Windows上的Safari不支持central
,但支持middle
,这仍然很好。
<?xml version="1.0"?>
<svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">
<path d="M 10 100 h 290" stroke="blue" stroke-width=".5" />
<text x="40" y="100" font-size="16" style="dominant-baseline: auto;">
XXX dominant-baseline: auto; XXX
</text>
<path d="M 10 200 h 290" stroke="blue" stroke-width=".5" />
<text x="40" y="200" font-family="sans-serif" font-size="15" style="dominant-baseline: central;">
XXX dominant-baseline: central XXX
</text>
</svg>
它似乎也不支持基线移位。 “-30%”值在支持它的浏览器中诀窍。 – 2011-04-01 12:11:12