0

I Googled this issue for about 30 minutes and was surprised nobody has asked so maybe it's not possible.

I'm using this line to embed the SVG file that I made in AI (note that when I saved the SVG, I had no fill OR stroke on the paths):

<object type="image/svg+xml" data="example.svg" height=600px width=600px>Your browser does not support SVG</object>

This obviously comes up with no image because the SVG file has no fill or stroke. I tried adding in

...fill=yellow>

or

...style="fill:yellow;">

but I'm not having any luck. Thanks!

4

2 回答 2

1

有一个不错的技巧:将其嵌入<img>并使用 javascript 将其转换为<svg>与此代码内联的代码(我认为来自 SO)。现在您可以操作这个 SVG 对象

代码: :

/* * Replace all SVG images with inline SVG */ jQuery('img.svg').each(function(){ var $img = jQuery(this); var imgID = $img.attr('id'); var imgClass = $img.attr('class'); var imgURL = $img.attr('src'); jQuery.get(imgURL, function(data) { // Get the SVG tag, ignore the rest var $svg = jQuery(data).find('svg'); // Add replaced image's ID to the new SVG if(typeof imgID !== 'undefined') { $svg = $svg.attr('id', imgID); } // Add replaced image's classes to the new SVG if(typeof imgClass !== 'undefined') { $svg = $svg.attr('class', imgClass+' replaced-svg'); } // Remove any invalid XML tags as per http://validator.w3.org $svg = $svg.removeAttr('xmlns:a'); // Replace image with new SVG $img.replaceWith($svg); }); });
于 2013-05-23T07:40:08.790 回答
0

您是否尝试在对象元素上添加填充或样式?如果是这样,那是行不通的。对象元素不支持这些属性。您必须将其添加到 SVG 文件中的 SVG 中。

于 2013-05-22T17:23:45.967 回答