简体   繁体   English

SVG内联CSS无法在Internet Explorer中显示

[英]SVG inline CSS not displaying in internet explorer

First question on stackoverflow, hope it's not too boneheaded. 关于stackoverflow的第一个问题,希望它不是太愚蠢。 I've been trying to figure out a way to display a calendar with split event days. 我一直试图想出一种方法来显示具有拆分事件日的日历。 What I came up with was using an SVG graphic placed with inline css as a background for the specific calendar table cell in order to split days that have a split. 我想到的是使用内嵌css放置的SVG图形作为特定日历表格单元格的背景,以便分割具有拆分的日期。 It works wonderfully in Firefox and Chrome but the graphics do not display in Internet explorer (I've tried 9 and 10 but not 11). 它在Firefox和Chrome中运行得非常好,但是图形不会显示在Internet Explorer中(我已经尝试过9和10但不是11)。

The calendar is first generated with javascript and events are placed by adding css classes to targeted cells from JSON data. 首先使用javascript生成日历,并通过将css类添加到来自JSON数据的目标单元格来放置事件。

Here is a small snip of the a CSS classes being used to apply the background, full example with the HTML in the fiddle: 下面是一个用于应用背景的CSS类的小片段,完整的示例包含小提琴中的HTML:

    .calendar td {
      position:relative;
    }

    .calendar .split {
        background-repeat:no-repeat;
        background-position: top left;
        background-size: 100% 100%;
    }
    .calendar .split.am_vaca{ background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'  preserveAspectRatio='none'><polygon points='0,0 1,0 0,1' style='stroke-width:0; fill:lightgreen;' /></svg>");}

Here is the fiddle containing the HTML and CSS that illustrates the issue: 这是包含HTML和CSS的小提琴,用于说明问题:

Running the fiddle in Firefox and chrome shows the split days properly but Internet explorer 9, 10, (11?) does not display the split days. 在Firefox和Chrome中运行小提琴会正确显示分割日,但Internet Explorer 9,10(11?)不会显示分割天数。

I have looked at similar questions such as the following but have not yet found any clear solutions: 我已经查看了类似的问题,如下所示,但尚未找到任何明确的解决方案:

  1. SVG background image in IE9 IE9中的SVG背景图像
  2. Inline SVG not working as background-image in IE 内联SVG在IE中不能用作背景图像

Anyone have any experience with getting Internet explorer to display inline SVG as a background or see something obvious I'm overlooking or maybe I'm approaching this the wrong way. 任何人都有任何使用Internet Explorer以显示内联SVG作为背景的经验,或者看到一些我忽略的东西,或者我正在以错误的方式接近它。 Thanks! 谢谢!

如果你base64编码数据,IE工作

    .calendar .split.pm_mgmt{ background-image: url("data:image/svg+xml;charset=utf8;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAxIDEnICBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSdub25lJz48cG9seWdvbiBwb2ludHM9JzEsMSAxLDAgMCwxJyBzdHlsZT0nc3Ryb2tlLXdpZHRoOjA7IGZpbGw6ZG9kZ2VyYmx1ZTsnIC8+PC9zdmc+");}

Unfortunately you need use URI encoding (or base64) for Internet Explorer. 不幸的是,您需要为Internet Explorer使用URI编码(或base64)。

With URI encoding you keep the posibility to change the SVG values, but it's hard to read. 使用URI编码,您可以保留更改SVG值的可能性,但很难阅读。

.calendar .split.am_vaca { background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%201%201'%20%20preserveAspectRatio%3D'none'%3E%3Cpolygon%20points%3D'0%2C0%201%2C0%200%2C1'%20style%3D'stroke-width%3A0%3B%20fill%3Alightgreen%3B'%20%2F%3E%3C%2Fsvg%3E"); }

You can encode your SVG here: http://pressbin.com/tools/urlencode_urldecode/ And choose the encodeURIComponent() option. 您可以在此处对SVG进行编码: http//pressbin.com/tools/urlencode_urldecode/并选择encodeURIComponent()选项。

If you are using Compass you can automate base64 encoding: http://keegan.st/2012/09/14/easy-image-data-uris-with-compass/ 如果您使用的是Compass,则可以自动执行base64编码: http//keegan.st/2012/09/14/easy-image-data-uris-with-compass/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM