简体   繁体   English

CSS背景中的IE10 SVG

[英]IE10 SVG in CSS background

I have a problem with IE10 and SVG in CSS style. 我在使用CSS样式的IE10和SVG时遇到问题。 It works on chrome and firefox: 它适用于chrome和firefox:

background-image: url(data:image/svg+xml,<svg\ version=\"1.1\"\ xmlns=\"http://www.w3.org/2000/svg\"\ width=\"32px\"\ height=\"32px\"\ viewBox=\"0\ 0\ 32\ 32\"><circle\ fill=\"red\"\ cx=\"16\"\ cy=\"16\"\ r=\"12\"/></svg>);

Here is my SVG example, but it doesn't work in IE10. 这是我的SVG示例,但在IE10中不起作用。 Are there any opportunities to resolve this problem? 有没有解决这个问题的机会? Unfortunately I have no opportunity to load SVG from HTML, it should be loaded from CSS like in example: 不幸的是,我没有机会从HTML加载SVG,应该从CSS加载,例如:

http://jsfiddle.net/fgLtkn1n/1/

 .foo { display:inline-block; width:32px; height:32px; border: 1px solid gray; background-image: url(data:image/svg+xml,<svg\\ version=\\"1.1\\"\\ xmlns=\\"http://www.w3.org/2000/svg\\"\\ width=\\"32px\\"\\ height=\\"32px\\"\\ viewBox=\\"0\\ 0\\ 32\\ 32\\"><circle\\ fill=\\"red\\"\\ cx=\\"16\\"\\ cy=\\"16\\"\\ r=\\"12\\"/></svg>); } 
 <div class='foo'></div> 

Thanks! 谢谢!

The only full cross-browser dataURI header I found is data:image/svg+xml; charset=utf8, 我发现的唯一完整的跨浏览器dataURI标头是data:image/svg+xml; charset=utf8, data:image/svg+xml; charset=utf8, . data:image/svg+xml; charset=utf8,

Also, you'll probably need to encodeURI your svg markup : 另外,您可能需要对svg标记进行encodeURI

 .foo { display:inline-block; width:32px; height:32px; border: 1px solid gray; background-image: url('data:image/svg+xml; charset=utf8, %3Csvg%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2232px%22%20height%3D%2232px%22%20viewBox%3D%220%200%2032%2032%22%3E%3Ccircle%20fill%3D%22red%22%20cx%3D%2216%22%20cy%3D%2216%22%20r%3D%2212%22%2F%3E%3C%2Fsvg%3E'); } 
 <div class='foo'></div> 

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

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