内联SVG的元素顺序是否重要? [英] Does element order matter for inline SVG?
问题描述
在Google Chrome 24中,如果在文档的后面定义了由< use>
元素引用的元素,则不会呈现它。我没有注意到有关 使用
元素。
In Google Chrome 24, if an element referenced by a <use>
element is defined later in the document it isn't rendered. I didn't notice anything related to element order in the documentation for the use
element.
这种行为是未定义的,不应该被期望在浏览器中保持一致或者只是Chrome中的一个bug?
Is this behavior undefined and shouldn't be expected to be consistent across browsers or just a bug in Chrome?
这个例子可以在下面看到(稍微修改一下这个问题)。蓝色的圆形像预期的那样呈现红色,不是那么多。我期望的Firefox 17和IE 9渲染两个圆圈。当相同的内容被引用为外部< img />
时,两个圆圈都会呈现。
An example of this can be seen below (slightly modified from this question). Blue circle renders as expected, red, not so much. Firefox 17 and IE 9 render both circles as I would expect. When the same content is referenced as an external <img />
, both circles render as well.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome use-tag bug?</title>
</head>
<body>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="200px" height="200px" viewBox="0 0 200 200">
<defs>
<g id="test2">
<circle cx="50" cy="50" r="25" fill="blue"/>
</g>
</defs>
<g>
<rect x="0.5" y="0.5" width="199" height="199" stroke="black" fill="none"/>
<use xlink:href="#test1" x="0" y="0"/>
<use xlink:href="#test2" x="0" y="0"/>
</g>
<defs>
<g id="test1">
<circle cx="100" cy="100" r="25" fill="red"/>
</g>
</defs>
</svg>
</body>
</html>
更新:似乎在Chrome 39中工作。
UPDATE: Seems to be working in Chrome 39.
推荐答案
渲染顺序依赖于元素顺序,因此它看起来像一个铬合:
SVG渲染顺序1.0,第2部分:语言
The Rendering Order depends on the element order, so it looks strong like a bug in chrome: SVG Rendering Order 1.0, Part 2: Language
这篇关于内联SVG的元素顺序是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!