我在Windows 10计算机上运行Internet Explorer 11时遇到了一个奇怪的问题.使用SVG图像作为背景显示为完全黑色,具有相同代码的Edge工作正常.
这里有一点小提琴再现我的问题
使用它,Edge正确渲染SVG,IE渲染只有黑色图像......我无法理解这种不同的行为!此外,在Windows 7机器IE11工作正常!
一些想法?先谢谢你们!
.icon-user-default {
width: 128px;
height: 128px;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiCgkgdmlld0JveD0iMCAwIDgwMCA4MDAiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDgwMCA4MDA7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPHN0eWxlIHR5cGU9InRleHQvY3NzIj4KCS5zdDB7ZmlsbDojODI3OTc3O30KCS5zdDF7ZmlsbDojN0I3MjcwO30KCS5zdDJ7Y2xpcC1wYXRoOnVybCgjU1ZHSURfMl8pO2ZpbGw6I0Q5QTc4Qzt9Cgkuc3Qze2NsaXAtcGF0aDp1cmwoI1NWR0lEXzJfKTtmaWxsOiNGMUYyRjI7fQoJLnN0NHtjbGlwLXBhdGg6dXJsKCNTVkdJRF8yXyk7ZmlsbDojRTZFN0U4O30KCS5zdDV7Y2xpcC1wYXRoOnVybCgjU1ZHSURfMl8pO30KCS5zdDZ7ZmlsbDojRUFDMEE3O30KCS5zdDd7ZmlsbDojRjJEN0JDO30KCS5zdDh7Y2xpcC1wYXRo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GNsYXNzPSJzdDUiPgoJCQk8cG9seWdvbiBjbGFzcz0ic3Q5IiBwb2ludHM9IjQwMCw2NjAuNiA0MjguOSw1NTAuMSA0NDMuOCw2MDAuNiAJCQkiLz4KCQkJPHBvbHlnb24gY2xhc3M9InN0MTAiIHBvaW50cz0iNDQ4LjMsNTMxLjEgNDI4LjYsNTUxLjYgNDQzLjgsNjAwLjYgNDcxLjgsNTY1LjkgCQkJIi8+CgkJPC9nPgoJCTxwYXRoIGNsYXNzPSJzdDExIiBkPSJNNDAwLDQ0Ni43YzIxLjMsMCwzOC41LTcsMzguNS0xNS43aC03Ny4xQzM2MS41LDQzOS43LDM3OC43LDQ0Ni43LDQwMCw0NDYuN3oiLz4KCTwvZz4KPC9nPgo8L3N2Zz4K)
}
确保设置背景大小的宽度和高度
背景尺寸:80px 60px;
在深入研究SVG文件结构后,我发现问题与SVG的样式属性有关.
在将图形另存为SVG文件时,Adobe Illustrator为我提供了四种声明样式表属性的选项
演示属性
样式属性
样式属性(实体参考)
风格元素
因此,关于SVG1.1'样式的W3C规范
使用前三种方式设置属性没有问题,但将样式表嵌入到元素内的SVG内容会导致问题!
这是我最后的小提琴测试结果
我希望对某人有所帮助......
如果像我一样,你的背景中有内联 SVG
(例如)
你需要确保你的编码是charset=utf8
(例如url(data:image/svg+xml;charset=utf8,
)
还要确保对保留的URL字符进行编码(例如<
=== %3C
和>
=== %3E
),并'
在属性周围使用单引号.
我也有这个问题.
在我的情况下,更改"样式"设置没有帮助,但取消选中Illustrator SVG导出对话框中的"响应"复选框,即使SVG中有内部CSS元素.
不同之处在于SVG元素需要width和height属性.
检查Illustrator SVG导出对话框中的"响应"复选框时,这些属性不存在.如果这真的是它的全部,那么它的命名很差,我想.
如果您使用inkscape或其他工具来制作SVG,我相信您的观察结果在此处添加时会很有价值.
因此,如果您希望CSS中的SVG背景图像在IE中正常工作,请确保SVG的根元素具有width和height属性.(例如,通过取消选中AI中的"响应"复选框).
宽度和高度属性不必须是正确的显示大小(其可以无论如何变化,经由CSS背景-size属性),但它们都必须是正确的纵横比.
如果您手动编写SVG标记,并且视图框的前两个值为零,那么您可以分别使用最后两个宽度和高度值.例如