SVG字母间距也适用于Mozilla Firefox

时间:2015-02-21 10:18:30

标签: css google-chrome firefox text svg

字母间距还有 SVG文字的另一种选择吗?

此代码在Chrome上运行

https://developer.mozilla.org/de/docs/Web/CSS/letter-spacing

正如您所看到的,由于存在错误,Firefox目前不支持它。但我真的需要在两个浏览器中使用字母间距。那么SVG文本还有很好的替代方案吗?

顺便说一下字间距。完全在Chrome中工作,但在Firefox上没有。

5 个答案:

答案 0 :(得分:17)

letter-spacing的另一种适用于Firefox的textLength属性。也许这适合你作为一种解决方法?



<svg width="10cm" height="3cm" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
  <desc>Example text01 - 'Hello, out there' in blue</desc>

  <text x="250" y="150" 
        font-family="Verdana" font-size="55" fill="blue" >
    Hello, out there
  </text>

  <text x="250" y="200" textLength="600"
        font-family="Verdana" font-size="55" fill="blue" >
    Hello, out there
  </text>

  <!-- Show outline of canvas using 'rect' element -->
  <rect x="1" y="1" width="998" height="298"
        fill="none" stroke="blue" stroke-width="2" />
</svg>
&#13;
&#13;
&#13;

答案 1 :(得分:4)

您可以使用参数“dx”。

<svg width="10cm" height="3cm" viewBox="0 0 1000 300"
    xmlns="http://www.w3.org/2000/svg" version="1.1">

    <text x="250" y="200" dx="0 20 20 20 20 0 20 20 20 20 20"
        font-family="Verdana" font-size="55" fill="blue" >
         Hello, out there
    </text>
</svg>

答案 2 :(得分:1)

我的解决方案是在QGIS中使用(多个)空格创建字符串。这是不好的方法,因为如果你想给所有元素一个更大的空间需要很长时间。

但它很容易并且以相同的方式适用于任何浏览器。因此,如果您在geojson或topojson中拥有数据,那么这就是您的选择。

答案 3 :(得分:0)

正常- InternetExplorer中只有两行文本存在问题-因此在实际的浏览器(如Chrome(√),Safari(√)和IE(√))中使用Leterspacing。只有Firefox ...

<svg fill="none" stroke="#838383" stroke-width="1" class="text-line"  width="100%" height="400">
                        <text fill="none" transform="translate(1 1)" textLength="1200"  >
                                <tspan x="0" y="192"><?php  the_field('ani_headline_1st');  ?></tspan>  
                                <tspan x="0" y="342"><?php  the_field('ani_headline_2nd');  ?></tspan>  
                        </text>

答案 4 :(得分:0)

Firefox(台式机)现在从73版开始支持letter-spacing属性。请参见the MDN page和相关bugzilla的浏览器兼容性。

Firefox for Android仍然不支持letter-spacing