在SVG中包含SVG文件 [英] Include SVG file in SVG

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

问题描述

我的SVG文件的defs部分中有一个linearGradient,并用fill =url(#myGradientName)引用它。到目前为止效果很好。

I've got a linearGradient in the defs section of my SVG file, and reference it with fill="url(#myGradientName)". That works great so far.

我想我应该能够将我的整个defs部分放在自己的SVG文件中,然后从我所有的SVG图像中引用它。也就是说:

I think I should be able to put my whole defs section in its own SVG file, and then just reference that from all my SVG images. That is, something like:

styles.svg:

styles.svg:

<svg xmlns=...>
  <defs>
    <linearGradient id="myGradient" ...>
    </linearGradient>
  </defs>
</svg>

image.svg:

image.svg:

<svg xmlns=...>
  <rect width="100" height="100" fill="styles.svg#myGradient"/>
</svg>

但我似乎无法应用这种风格。我对此文件外部的ID(styles.svg#myGradient)有错误的语法吗?我是否需要以某种方式明确地包含该文件?

But I can't seem to get the style to apply. Do I have the wrong syntax for IDs external to this file (styles.svg#myGradient)? Do I need to explicitly include the file first somehow?

我一直在倾注SVG规范,看起来这应该是可能的,但实际上没有一个例子显示它已完成。

I've been pouring over the SVG spec and it looks like this should be possible, but none of the examples actually show it being done.

编辑: FOP常见问题表明正确的语法是fill =url(grad.svg#PurpleToWhite),但这在Gecko或Webkit中不起作用。这是正确的,没有人支持它,或者我做错了什么?

The FOP FAQ suggests that the correct syntax is fill="url(grad.svg#PurpleToWhite)", but that doesn't work in Gecko or Webkit. Is that correct and nobody supports it, or am I doing something else wrong?

推荐答案

看起来这只是在< a href =https://developer.mozilla.org/web-tech/2008/10/10/svg-external-document-references/ =nofollow noreferrer> Firefox 3.1 。

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

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