【发布时间】:2018-02-06 20:42:18
【问题描述】:
我无法显示数据:image svg。
在我的网站上,我使用这个 css sn-p:
#menu > .close:before, #menu > .close:after {
-moz-transition: opacity 0.2s ease;
-webkit-transition: opacity 0.2s ease;
-ms-transition: opacity 0.2s ease;
transition: opacity 0.2s ease;
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: 2em 2em;
}
#header nav ul li a[href="#menu"]:before {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cstyle%3Eline %7B stroke-width: 8px%3B stroke: %23f2849e%3B %7D%3C/style%3E%3Cline x1='0' y1='25' x2='100' y2='25' /%3E%3Cline x1='0' y1='50' x2='100' y2='50' /%3E%3Cline x1='0' y1='75' x2='100' y2='75' /%3E%3C/svg%3E");
opacity: 0;
}
#header nav ul li a[href="#menu"]:after {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cstyle%3Eline %7B stroke-width: 8px%3B stroke: %23585858%3B %7D%3C/style%3E%3Cline x1='0' y1='25' x2='100' y2='25' /%3E%3Cline x1='0' y1='50' x2='100' y2='50' /%3E%3Cline x1='0' y1='75' x2='100' y2='75' /%3E%3C/svg%3E");
opacity: 1;
}
它在 Chrome 中正确显示,过去在 Firefox 57 中也可以正确显示。但是随着 Firefox 58 的新更新,不再显示 svg 文件。所以我查看了它,在检查 Firefox 中的布局文件时,我看到上面的行被 Base64 编码为例如
background-image: url("data:image/svg+xml;charset=utf8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+PHN0eWxlPmxpbmV7c3Ryb2tlLXdpZHRoOjhweDtzdHJva2U6IzU4NTg1OH08L3N0eWxlPjxwYXRoIGQ9Ik0wIDI1SDFlMnoiIC8+PHBhdGggZD0iTTAgNTBIMWUyeiIgLz48cGF0aCBkPSJNMCA3NUgxZTJ6IiAvPjwvc3ZnPg==");
不会显示 svg 文件。我不知道如何解决这个问题。也许有人有一个想法。谢谢。
【问题讨论】:
-
我无法复制它,您的 SVG 在我的 Firefox/58.0.1 Win64 (demo) 副本中渲染得很好。您确定错误不在其他地方吗? DOM 检查器不反映实际的源代码,它只是内存中对象的漂亮打印表示。