aan*_*s77 3 css svg internet-explorer-11 inline-svg
我在CSS中将以下嵌入式SVG定义为背景图像。
div {
border: 1px solid black;
background-image: url("data:image/svg+xml;charset=utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 10 10'> <path d='M2 10 L8 0 L10 0 L10 10' fill='%238A92DF'></path></svg>");
background-repeat: no-repeat;
background-position: center center;
background-size: 100%;
}
Run Code Online (Sandbox Code Playgroud)
它在Chrome,Firefox和Edge中可以正常运行,但在Internet Explorer 11中却无法运行。为什么?
您必须使用完整的URL编码svg。
如果您使用的是VSCode,则有一个名为“ URL编码”的扩展将为您执行此操作...或者您可以在网上轻松找到一个扩展名:https://meyerweb.com/eric/tools/dencoder/
请注意,我还删除了“版本”属性和“; charset = utf8”部分,不确定是否需要,但要进行清理...
div {
border: 1px solid black;
background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2010%2010'%3E%3Cpath%20d%3D'M2%2010%20L8%200%20L10%200%20L10%2010'%20fill%3D'%238A92DF'%3E%3C%2Fpath%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: center center;
background-size: 100%;
width: 500px;
height: 500px;
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)