SVG中的下标和上标 [英] subscripts and superscripts in SVG

查看:353
本文介绍了SVG中的下标和上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从此站点显示 的SVG上标和上标

I am trying to display sub- and superscripts with SVG using the following code from this site

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
    <text x = "10" y = "25" font-size = "20">
        <tspan>
            e = mc 
            <tspan baseline-shift = "super">2</tspan>
        </tspan>
        <tspan x = "10" y = "60">
            T 
            <tspan baseline-shift = "sub">i+2</tspan>
            =T 
            <tspan baseline-shift = "sub">i</tspan>
            + T 
            <tspan baseline-shift = "sub">i+1</tspan>
        </tspan>
    </text>
</g>

,但子/上标不显示在IE或Firefox中.这是未实现的还是存在其他问题? [您能看到下标显示正确吗?]

but the sub/superscripts do not display in IE or Firefox. Is this unimplemented or is there another problem? [Are you able to see the subscripts displayed properly?]

推荐答案

IE9,IE10和Firefox不支持基线转换,请参阅:

Baseline-shift is not supported in IE9, IE10, and Firefox, see:

http://msdn.microsoft.com/en-us/library/gg558060(v=vs.85).aspx https://bugzilla.mozilla.org/show_bug.cgi?id=308338

如果您敏锐地尝试显示公式,则更适合将SVG嵌入MathML,请参见:

If you're acually trying to display formulas, a better fit would be MathML embedded within SVG, see:

http://www.maths-informatique-jeux.com/international/mathml_with_other_standards/index.php

如果您想为所提供的示例提供快速修复,则可以使用dy ...

If you want a quickfix for the example you provided, you can emulate baseline-shift with dy...

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
    <text x = "10" y = "25" font-size = "20">
        <tspan>
            e = mc 
            <tspan dy ="-10">2</tspan>
        </tspan>
        <tspan x = "10" y = "60">
            T 
            <tspan dy="10">i+2</tspan>
            <tspan dy="-10">=T </tspan>
            <tspan dy="10">i</tspan>
            <tspan dy="-10">+ T</tspan> 
            <tspan dy="10">i+1</tspan>
        </tspan>
    </text>
    </g>
</svg>

http://jsfiddle.net/UQ5Dp/

这篇关于SVG中的下标和上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆