【发布时间】:2014-09-07 09:18:30
【问题描述】:
我正在使用一种使用自定义字体的 SVG 模式,以便在 HTML 页面上使用该模式作为背景图像。
在 Chrome 和 Safari 中一切正常,但在 Firefox 中开始变得有趣:
- 当我打开 SVG 文件本身时,Firefox 可以很好地呈现 SVG 和自定义字体文本(到目前为止一切都很好!);
- 但是,当同一个 SVG 文件用作 HTML 元素的背景时,Firefox 确实不呈现自定义字体 (!)
我已经花了几个小时试图找出问题所在,欢迎换一双眼睛。
简而言之:
CSS:
@import url(http://fonts.googleapis.com/css?family=Indie+Flower);
body {
background: url(pattern-google.svg);
}
SVG 文件:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" height="200" width="200">
<style type="text/css">@import url(http://fonts.googleapis.com/css?family=Indie+Flower);</style>
<defs>
<!-- Geometry -->
<g>
<rect id="square" x="0" y="0" width="200" height="200" />
</g>
<!-- Patterns with Text -->
<pattern id="pattern" x="0" y="0" width="40" height="40" patternUnits="userSpaceOnUse" text-anchor="middle" font-size="20" font-family="Indie Flower, sans-serif" style="font-family: Indie Flower, sans-serif;">
<rect x="00" y="00" width="40" height="40" fill="transparent" />
<text x="00" y="00" fill="#777">S</text>
<text x="40" y="00" fill="#777">S</text>
<text x="20" y="20" fill="#777">S</text>
<text x="00" y="40" fill="#777">S</text>
<text x="40" y="40" fill="#777">S</text>
</pattern>
</defs>
<!-- Graphics -->
<use xlink:href="#square" transform="translate(0, 0)" fill="url(#pattern)"/>
</svg>
HTML 本身并不重要,但我在下面链接了它。 我最终没有生成 jsfiddle,因为我无法在其中托管 SVG 文件。
(在演示之外,这里的实际应用程序是我想使用自定义字体来显示音标。(作为背景图像,以帮助人们学习它们。)在 SVG 中这样做可以省去我每当我对设计进行更改时,都可以导出到位图。)
【问题讨论】:
-
从 Firefox 46.0.1(或者更早的版本)开始,问题就消失了。
标签: html css firefox svg background-image