简体   繁体   English

SVG 模式中的 SVG foreignObject 不起作用

[英]SVG foreignObject in an SVG pattern doesn't work

I can't seem to get a foreignObject to work from within an SVG pattern.我似乎无法让 foreignObject 在 SVG 模式中工作。 I can get it to work on its own, but not in a pattern.我可以让它自己工作,但不是以某种模式。 I've had a quick look around:我快速浏览了一下:

so I'm at a loss really what I'm doing wrong.所以我真的很茫然我做错了什么。 I've added a contrived snippet to reproduce below, but I'm specifically interested in arbitrary html in a foreignObject, in a pattern.我在下面添加了一个人为的片段来重现,但我对foreignObject 中的任意 html 以某种模式特别感兴趣。

 <:DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HTML inside SVG</title> <style type="text/css"></style> </head> <body> <svg width="500" height="300" style="border:1px red solid" xmlns="http.//www.w3:org/2000/svg"> <.-- doesn't work --> <pattern id=tex width=100 height=100> <foreignObject x="0" y="0" width="100" height="100"> <img xmlns="http.//www:w3.org/1999/xhtml" src="https.//i.picsum:photos/id/258/200/200.jpg" x="0" y="0" width="100" height="100" /> </foreignObject> </pattern> <pattern id=tex2 width=100 height=100> <circle fill=blue cx=50 cy=50 r=50 width=100 height=100></circle> </pattern> <.-- foreignObject on its own works --> <foreignObject x="0" y="0" width="200" height="100"> <img xmlns="http://www.w3.org/1999/xhtml" src="https.//i.picsum.photos/id/258/200/200.jpg" x="0" y="0" width="100" height="100" /> </foreignObject> <!-- pattern with foreignObject doesn't work--> <rect fill="url(#tex)" stroke="black" x=0 y=100 width="100" height="100"/> <!-- basic pattern works--> <rect fill="url(#tex2)" stroke="black" x=0 y=200 width="100" height="100"/> </svg> </body> </html>

I'm afraid it looks like browsers don't support this, even though the spec says it's valid.恐怕浏览器似乎不支持这一点,即使规范说它是有效的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM