【发布时间】:2016-05-18 16:28:40
【问题描述】:
我发现这个 svg 在 Chrome、Firefox 和 IE11 中可以正确呈现:
background:#000 url('data:image/svg+xml;utf8,<svg width="42px" height="42px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><circle cx="21px" cy="21px" r="21" fill="black"/><rect x="9px" y="10px" width="25px" height="22px" fill="white"/></g></svg>');
但是,我无法让这些 svg 图标跨浏览器工作:
这适用于 Chrome 和 Firefox,但不适用于 IE11:
background:#000 url('data:image/svg+xml;utf8,<svg width="42px" height="42px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"><g><circle cx="21px" cy="21px" r="21px" fill="black"/><g><polyline points="20 30 15 20 25 15 20 7" stroke="white" stroke-width="2"/><circle cx="20" cy="30" r="2.2" fill="white" stroke="white"/><circle cx="20" cy="7" r="2.2" fill="white" stroke="white"/></g></g></svg>');
}
我发现这个 svg 仅适用于 Chrome:
background:#000 url('data:image/svg+xml;utf8,<svg width="42" height="42" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><circle r="21" id="svg_2" cy="21" cx="21" fill="#050404"/><path id="svg_3" d="m52.86,21.00981l6.42885,-13.71338l17.14235,0l6.42882,13.71338l-6.42882,13.71425l-17.14235,0l-6.42885,-13.71425z" fill="#ffffff"/></g></svg>');
}
有没有办法让这些 svg 跨浏览器工作。我使用这些基于this的svgs
我尝试了以下组合:
background:black url('data:image/svg+xml;utf8,<svg width="42px" height="42px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><circle cx="21px" cy="21px" r="21" fill="black"/><rect x="9px" y="10px" width="25px" height="22px" fill="white"/></g></svg>'),linear-gradient(transparent, transparent);
background:%23000 url('data:image/svg+xml;utf8,<svg width="42px" height="42px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><circle cx="21px" cy="21px" r="21" fill="black"/><rect x="9px" y="10px" width="25px" height="22px" fill="white"/></g></svg>'),linear-gradient(transparent, transparent);
我也尝试使用这里建议的后备,但它总是呈现 png:
body {
background: url(fallback.png);
background: url(background.svg),
linear-gradient(transparent, transparent);
}
【问题讨论】:
-
你试过检查控制台吗?
-
@Justinas 我做了,是否有任何关于 CSS 的消息?我没有找到。
-
我看到了一些不同的行为。第一个似乎在我的 IE11 (Win7) 上不起作用,第三个在 Chrome 中对我来说也只是显示黑色(我只是将 CSS 应用于小提琴的主体)。
标签: css firefox svg internet-explorer-11