SVG图标未在IE 11 / Edge中显示

时间:2018-03-15 14:21:56

标签: internet-explorer svg data-uri

我在我的应用中使用以下CSS来显示SVG图标:

.edit {
  padding-right: 1em;
  background-image: url('data:image/svg+xml;utf8, <svg version="1.1" 
id="Inhalt" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" 
height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" 
xml:space="preserve"> <path d="M93.2,28.2l4.399-4.3c0.601-0.6,0.601-1.5,0-
2.1l-18-18.1c-0.6-0.6-1.5-0.6-2,0L73.2,8.1L93.2,28.2z"/><polygon 
points="18.1,62.2 68.1,13 88.2,33.2 38.3,82.4 "/><polygon points="12.5,68 
2.3,97.9 32.3,87.8 "/></svg>');
  background-repeat: no-repeat;
  background-size: 100% 100%;

}

然后在我的html代码中使用它:

 <span class=edit>This is the edit button</span>

我已经确认IE中的文档模式是Edge / Standard。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

在数据URI中使用SVG时,需要正确转义SVG。请参阅此工具(以及它链接到的博客文章):

https://codepen.io/jakob-e/pen/doMoML

.edit {
  width: 200px;
  height: 200px;
  padding-right: 1em;
  background-image: url("data:image/svg+xml,%3Csvg version='1.1' id='Inhalt' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='100px' height='100px' viewBox='0 0 100 100' enable-background='new 0 0 100 100' xml:space='preserve'%3E %3Cpath d='M93.2,28.2l4.399-4.3c0.601-0.6,0.601-1.5,0- 2.1l-18-18.1c-0.6-0.6-1.5-0.6-2,0L73.2,8.1L93.2,28.2z'/%3E%3Cpolygon points='18.1,62.2 68.1,13 88.2,33.2 38.3,82.4 '/%3E%3Cpolygon points='12.5,68 2.3,97.9 32.3,87.8 '/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
<div class="edit"></div>