Apply styles to an imported SVG [duplicate] - html

This question already has answers here:
How to apply a style to an embedded SVG?
(6 answers)
Closed 7 years ago.
I have a database that outputs an object with an SVG referenced within it. Inside this SVG I've got an external style sheet and what I would like to do is reference the class of in this SVG imported style sheet so I can colour the icons appropriately.
At the moment it doesn't appear to recognise the class of the object at all and I wondered if this was even possible?
Alternatively, is there any way I could apply a dynamically named id or class to part of the svg code that's imported via object, which I could then reference using the stylesheet.
Here is a snippet of the HTML:
<object class="getFit" type="image/svg+xml" data="../images/well-being/imageurl">
Your browser does not support SVG</object>
The SVG:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<?xml-stylesheet type="text/css" href="../../well#york/svg-health.css" ?>
<svg version="1.2" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" width="128px" height="128px" viewBox="0 0 128 128" xml:space="preserve">
<g id="_x31_28px_boxes">
<rect fill="none" width="128" height="128"/>
</g>
<g id="Production">
<g>
<path d="M47.9005,68.2746l-7.8831,11.5446L19.607,81.4577c-8.0373,0.6451-7.0919,12.8251,0.9781,12.1809
l23.3208-1.8721c1.8405-0.1478,3.5156-1.12,4.5568-2.6449l6.9434-10.1685C51.7793,76.2057,48.8114,72.7493,47.9005,68.2746z"/>
<path d="M111.0477,57.7956l-14.9185-2.9008C86.0095,31.5106,87.623,33.068,57.7699,25.3819
c-1.2517-0.3173-2.6302-0.0971-3.7574,0.7207L37.0909,38.3789c-3.719,2.6923-0.1874,8.4495,3.8984,6.3709l16.4271-8.357
l10.1408,2.6252c-3.2134,5.3099-0.6341,1.3988-13.1933,19.7913c-3.6807,6.4816-2.3874,11.5738,3.6894,16.2671l0.0034-0.005
c0.106,0.0745,16.7525,10.2843,16.7525,10.2843l-9.1826,24.4947c-2.8514,7.6054,8.6288,11.7947,11.4423,4.2895l10.9522-29.2146
c1.0273-2.7405-0.033-5.8246-2.5283-7.3541l-15.6026-9.5634l12.6636-17.919C82.588,50.1536,88.638,61.782,88.638,61.782
c0.6839,1.2147,1.9524,2.0668,3.4475,2.1532l18.0603,1.0444C114.6242,65.2435,115.4678,58.6551,111.0477,57.7956z"/>
<path d="M94.179,31.8982c5.9954-1.2801,9.8316-7.1943,8.553-13.1839c-1.2356-5.8638-7.077-9.8554-13.1953-8.5549
c-5.9856,1.2878-9.8276,7.21-8.562,13.2012C82.2281,29.2015,88.0569,33.2142,94.179,31.8982z"/>
</g>
</g>
</svg>
My CSS:
#charset "utf-8";
/* CSS Document */
.getFit path, object.getFit circle
{
fill:#ff5000;
}
.eatWell path, object.eatWell circle
{
fill:#009F14;
}
.feelGood path, object.feelGood circle
{
fill:#ffc200;
}

When using object the content is confined to its document.
How to apply external stylesheet to an embedded SVG?
What you are trying to do is even more complicated.
but it is possible.
If each of your icons gets a css file then you can use javascript to add a stylesheet to your svg document when its loaded.
var svgobject = document.getElementsByClassName(".getFit");
for (var i=0; i<svgObject.length; i++)
var svgDoc = svgObject[i].contentDocument;
var linkElm = svgDoc.createElementNS("http://www.w3.org/1999/xhtml", "link");
linkElm.setAttribute("href", "getFitStyle.css");
linkElm.setAttribute("type", "text/css");
linkElm.setAttribute("rel", "stylesheet");
svgDoc.getElementById("where-to-insert").appendChild(linkElm);
}

Related

How do I set the margin for an SVG in WP Nav menu?

I've been on the stuggle bus trying to accomplish inserting an SVG graphic as a menu item in my wordpress header navigation. I found this useful function in another answered question. However, now that I've managed to insert my SVG successfully, I don't seem to be able to resize the container it is in and it's shoving my other menu items much too far to the right.
Here's the markup I used to insert my SVG (THANKS to user #bramchi for this!):
Add the %FANCY_SVG% string to a menu item label in the Wordpress admin.
Define the filter as follows:
function find_replace_my_fancy_svg( $items, $args ) {
$items = str_replace(
'%FANCY_SVG%',
'<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.5.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_2_00000039817196845372784110000000279607806379935920_"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px";" xml:space="preserve">
<style type="text/css">
.st0{fill:#C10230;}
</style>
<g id="Layer_1-2">
<path class="st0" d="M23.7,18.5H5.8c-1.2,0-2.3-1-2.3-2.3V3.7L0.4,1.6C0,1.3-0.1,0.8,0.1,0.4C0.4,0,0.9-0.1,1.3,0.1l3.9,2.7v13.4
c0,0.3,0.2,0.5,0.5,0.5h17.8c0.5,0,0.9,0.4,0.9,0.9S24.1,18.5,23.7,18.5z M6.1,4.7v9.5c0,0.9,0.8,1.7,1.7,1.7h17.4
c0.8,0,1.5-0.6,1.6-1.3L30,5.1c0.2-1-0.6-2-1.6-2H7.8C6.9,3.1,6.1,3.8,6.1,4.7z M8.1,19.6c-0.9,0-1.6,0.7-1.6,1.6s0.7,1.6,1.6,1.6
c0.9,0,1.6-0.7,1.6-1.6S9,19.6,8.1,19.6z M21.5,19.6c-0.9,0-1.6,0.7-1.6,1.6s0.7,1.6,1.6,1.6s1.6-0.7,1.6-1.6S22.4,19.6,21.5,19.6z
"/>
</g>
</svg>',
$items
);
return $items;
}
add_filter( 'wp_nav_menu_items', 'find_replace_my_fancy_svg', 10, 2 );
Here's my site: www.716apparelco.com
I can see when I inspect that there's a container that is 300px x 150px but I'm not sure what that container is named to target it to set my margins(?)/padding(?)/container size(?)
It's the little cart icon that I'm trying to manipulate. Probably very simple to do for someone who isn't a newb like me. ????

SVG icons not sizing to bounding box from export

I am using Google Material icons for a project and exporting the icons using Figma.
In the Angular application I am using a sprite sheet to reference each icon like so:
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol viewBox="0 0 24 24" id="icon-someIcon">
<title>Some Icon</title>
<path fill="currentColor" d="paths..."/>
</symbol>
<symbol viewBox="0 0 24 24" id="icon-anotherIcon">
<title>Another Icon</title>
<path fill="currentColor" d="paths...." />
</symbol>
</svg>
CSS definition.
svg.icon{
display: inline-block;
width: 47px;
height: 47px;
fill: #000;
}
svg-icon.component.html
<svg attr.fill="{{ fill }}" attr.class="{{ iconClass }}">
<use attr.href="assets/{{ sheetType }}-sprite-sheet.svg#{{ icon }}"></use>
</svg>
svg-icon-component.ts
export class SvgIconComponent {
#Input() icon!: string;
#Input() fill?: string;
#Input() iconClass?: string;
#Input() sheetType: 'primary' | 'secondary' = 'primary';
}
In the child component
<app-svg-icon
[icon]="iconName"
[iconClass]="'icon'"
></app-svg-icon>
What I am currently receiving is a misaligned icon inside the bounding box making alignment of the icons very difficult/impossible. The SVG icon does not fill the bounding box but rather has a static size that it was imported at, and the viewbox gets changed to allow the icon to be fully visible and not clipped rather than expand with the size of the icon.
Even exporting the vector from Figma, without any kind of viewbox/bounding box, I still run into the vector dimensions being static and initially fixed rather than being defined by the SVG styling.

Unable to override fill property on SVG icon using React

I have a bunch of icons I have exported from Figma and I would like to create a wrapper Component around those icons, using the benefit of <use> tag.
So I created a SVG file with all the symbols in order to target them by their id.
The problem is, I am not able to override the fill property on the reused icons. After a lot of reading, I know that I'm supposed to use CSS inheritance since the reused element is in the shadow DOM and its properties cannot be accessed as usual.
Just for debugging purposes, I copy pasted the source code of one of those icons directly in the component (and not using the import mechanism), and surprisingly, it works.
Here is the code :
icon.svg
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="ic">
<path fill="#000" d="M81,40.933c0-4.25-3-7.811-6.996-8.673c-0.922-5.312-3.588-10.178-7.623-13.844 c-2.459-2.239-5.326-3.913-8.408-4.981c-0.797-3.676-4.066-6.437-7.979-6.437c-3.908,0-7.184,2.764-7.979,6.442 c-3.078,1.065-5.939,2.741-8.396,4.977c-4.035,3.666-6.701,8.531-7.623,13.844C22.002,33.123,19,36.682,19,40.933 c0,2.617,1.145,4.965,2.957,6.589c0.047,0.195,0.119,0.389,0.225,0.568l26.004,43.873c0.383,0.646,1.072,1.04,1.824,1.04 c0.748,0,1.439-0.395,1.824-1.04L77.82,48.089c0.105-0.179,0.178-0.373,0.225-0.568C79.855,45.897,81,43.549,81,40.933z M49.994,11.235c2.164,0,3.928,1.762,3.928,3.93c0,2.165-1.764,3.929-3.928,3.929s-3.928-1.764-3.928-3.929 C46.066,12.997,47.83,11.235,49.994,11.235z M27.842,36.301c0.014,0,0.027,0,0.031,0c1.086,0,1.998-0.817,2.115-1.907 c0.762-7.592,5.641-13.791,12.303-16.535c1.119,3.184,4.146,5.475,7.703,5.475c3.561,0,6.588-2.293,7.707-5.48 c6.664,2.742,11.547,8.944,12.312,16.54c0.115,1.092,1.037,1.929,2.143,1.907c2.541,0.013,4.604,2.087,4.604,4.631 c0,1.684-0.914,3.148-2.266,3.958H25.508c-1.354-0.809-2.268-2.273-2.268-3.958C23.24,38.389,25.303,36.316,27.842,36.301z M50.01,86.723L27.73,49.13h44.541L50.01,86.723z"/>
</symbol>
</svg>
LocalIcon.css
.icon {
width: 100px;
height: 125px;
}
use.ic-1 {
fill: skyblue;
}
use.ic-2 {
fill: #FDC646;
}
svg path {
fill: inherit;
}
LocalIcon.js
import React, { FC } from 'react';
import Icons from '../../icons/ic.svg';
import './LocalIcon.css';
const LocalIcon = ({ name, color, size }) => (
// <svg fill={color} width={size} height={size}>
// <use className="icon" xlinkHref={`${Icons}#Icon/Heart/Filled`}/>
// </svg>
<>
<svg>
<symbol id="ic">
<path fill="#000" d="M81,40..."/>
</symbol>
</svg>
<svg className='icon' viewBox='0 0 100 125'>
<use className='ic-1' href={`${Icons}#ic`} x='0' y='0' /> // This one is still black
</svg>
<svg className='icon' viewBox='0 0 100 125'>
<use className='ic-2' href='#ic' x='0' y='0' /> // This one works
</svg>
</>
);
Does someone have an idea about what am I doing wrong ? Is that somehow related to the way I import the file ? Thanks a lot for your help.
In order for your CSS rule to apply,
you need to change any fill rule in your SVG code to fill:'inherit'. Otherwise, the SVG style will override your CSS style.

SVG with USE tag not rendering

The DOM already includes an empty SVG tag (svg). When I try to dynamically append a USE tag of an existing SVG symbol (symbol) with an id (iconId):
svg.empty();
svg[0].setAttribute('viewBox', symbol.getAttribute('viewBox'));
svg.append('<use xlink:href="#' + iconId + '"></use>');
it no longer renders the SVG. In Chrome, it renders if I add:
element.html(element.html());
or manually manipulate the viewBox attribute, but that's not a real solution and IE doesn't like it at all.
It's worth mentioning that if I append SVG graphics directly, the element renders.
What is happening here and why isn't the SVG drawing after appending the USE tag?
After all it was indeed a matter of namespaces.
Specifically, SVG elements and attributes must be created and set using document.createElementNS and node.setAttributeNS.
$(document).ready(function(evt) {
var svgns = 'http://www.w3.org/2000/svg',
xlinkns = 'http://www.w3.org/1999/xlink',
use = document.createElementNS(svgns, 'use');
use.setAttributeNS(xlinkns, 'xlink:href', '#save');
document.getElementById('useSVG').appendChild(use);
});
#svgStore {
display: none;
}
#useSVG {
width: 16px;
height: 16px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<svg style="display:none;" id="svgStore" style="display: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<symbol viewBox="0 0 16 16" id="save"><title>save</title> <g id="svgstore3748a955346b4a088bbdc55a22f56504_x31_6_13_">
<path style="fill-rule:evenodd;clip-rule:evenodd;" d="M9,4h2V2H9V4z M13,13H3v1h10V13z M13,11H3v1h10V11z M13,0H0v16h16V3L13,0z
M3,1h9v4H3V1z M14,15H2V8h12V15z M13,9H3v1h10V9z">
</path>
</g>
</symbol>
</svg>
SVG use:
<svg id="useSVG" xmlns="http://www.w3.org/2000/svg"></svg>
Thanks to #RobertLongson and http://www.kevlindev.com/tutorials/basics/shapes/js_dom/ for directing to the answer.

Chrome not rendering SVG referenced via <img> element

I am having issues with google chrome not rendering svg with an img element. This happens when refreshing the page and initial page load. I can get the image to show up by "Inspecting Element" then right clicking the svg file and opening the svg file in a new tab. The svg image will then be rendered on the original page.
<img src="../images/Aged-Brass.svg">
Totally at loss here as to what the issue is. The svg image renders fine in IE9 and FF just not in Chrome or Safari.
I have my MIME types set as well. (image/svg+xml)
EDIT:
Here is a simple html page that I built to help illustrate my issue.
<!DOCTYPE html>
<html>
<head>
<title>SVG Test</title>
<style>
#BackgroundImage{
background: url('../images/Aged-Brass.svg') no-repeat scroll left top;
width: 400px;
height: 600px;
}
#image_element {
width: 400px;
height: 600px;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="image_element">
<img src="../images/Aged-Brass.svg">
</div>
<div id="BackgroundImage"></div>
</body>
</html>
As you can see I am trying to use an svg file in both an img element and in css as a background image. Neither work on the initial page load in chrome or safari. When I inspect element right click svg or click link to svg load in another window the svg file will render in original tab.
A simple and easy way; according to
https://css-tricks.com/forums/topic/svg-css-background-image-not-showing-in-chrome/
You have to open the .SVG file with a text editor (like notepad) and change
xlink:href="data:img/png;base64,
to:
xlink:href="data:image/png;base64,
it worked for me!
The svg-tag needs the namespace attribute xmlns:
<svg xmlns="http://www.w3.org/2000/svg"></svg>
i came here because i had the same problem,
when i inspect the element i can see the file, but on the site i can't (even when using localhost)
the answer to my problem was in saving the SVG file.
If you saved it from illustrator make sure to click 'embed' and not 'link'. as link will just refer to your local files rather than include the data (If i understand it correctly).
I read about it on the adobe website which has some other useful tips for exporting
http://www.adobe.com/inspire/2013/09/exporting-svg-illustrator.html
This worked for me, hope it was useful.
I came here because I had a similar problem, the image was not being rendered. What I found out was that the content type header of my testing server wasn't correct. I fixed it by adding the following to my .htaccess file:
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
Use <object> instead (of course, replace each URL with your own):
.BackgroundImage {
background: url('https://upload.wikimedia.org/wikipedia/commons/b/bd/Test.svg') no-repeat scroll left top;
width: 400px;
height: 600px;
}
<!DOCTYPE html>
<html>
<head>
<title>SVG Test</title>
</head>
<body>
<div id="ObjectTag">
<object type="image/svg+xml" data="https://upload.wikimedia.org/wikipedia/commons/b/bd/Test.svg" width="400" height="600">
Your browser does not support SVG.
</object>
</div>
<div class="BackgroundImage"></div>
</body>
</html>
I had a similar problem and the existing answers to this either weren't applicable, or worked but we couldn't use them for other reasons. So I had to figure out what Chrome disliked about our SVGs.
In our case in turned out to be that the id attribute of the symbol tag in the SVG file had a : in it, which Chrome didn't like. Soon as I removed the : it worked fine.
Bad:
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 72 72">
<defs>
<symbol id="ThisIDHasAColon:AndChromeDoesNotLikeIt">
...
</symbol>
</defs>
<use
....
xlink:href="#ThisIDHasAColon:AndChromeDoesNotLikeIt"
/>
</svg>
Good:
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 72 72">
<defs>
<symbol id="NoMoreColon">
...
</symbol>
</defs>
<use
....
xlink:href="#NoMoreColon"
/>
</svg>
Adding the width attribute to the [svg] tag (by editing the svg source XML) worked for me:
eg:
<!-- This didn't render -->
<svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
...
</svg>
<!-- This did -->
<svg version="1.1" baseProfile="full" width="1000" xmlns="http://www.w3.org/2000/svg">
...
</svg>
I had this problem when i exported images from figma. Check source code of svg, if you have colon : in ids like this: id="paint1_linear_23:318" it'll make you the problems with rendering in chrome.
Just remove all colons in ids.
Don't forget make the same with referring to this ids like this: fill="url(#paint1_linear_23:318)".
.svg image does not have it's initial height and width. Therefore it is not visible. You have to set it.
You can do either in-line or in css file:
In-line:
<img src="../images/Aged-Brass.svg" class="image" alt="logo" style="width: 100px; height: 50px;">
Css file:
<img src="../images/Aged-Brass.svg" class="image" alt="logo">
.image {
width: 100px;
height: 50px;
}
Just replace <img> tag to <object> tag for SVG image.
<object data="assets/twitter-wrap.svg" type="image/svg+xml"></object>
I had the same problem. This problem was solved when I checked the file type that was accepted and set in headers "Content-Type", "image/svg+xml":
response.setHeader("Content-Type", "image/svg+xml");
I was able to use your sample to create a test page, and it worked just fine. My assumption is that there is something wrong with your svg file. Can you paste that here as well? Here is the sample I used.
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
<g>
<title>Layer 1</title>
<ellipse ry="30" rx="30" id="svg_1" cy="50" cx="50" stroke-width="5" stroke="#000000" fill="#FF0000"/>
</g>
</svg>
looks like a Chrome bug,
i did something else as i almost got crazy because of this...
using Chrom debugger if you change the css of the svg object it shows on the screen.
so what i did was:
1. check for screen size
2. listen to the "load" event of my SVG object
3. when the element is loaded i change its css using jQuery
4. it did the trick for me
if (jQuery(window).width() < 769) {
jQuery('object#mysvg-logo')[0].addEventListener('load', function() {
jQuery("object#mysvg-logo").css('width','181px');
}, true);
}
width: 180px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<object id="mysvg-logo" type="image/svg+xml" data="my svg logo url here">Your browser does not support SVG</object>
In my case this problem persisted when I created and saved the svg using Photoshop.
What helped, was opening the file using Illustrator and exporting the svg afterwards.
I also got the same issue with chrome, after adding DOCTYPE it works as expected
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Before
<?xml version="1.0" encoding="iso-8859-1"?>
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="792px" height="792px" viewBox="0 0 792 792" style="enable-background:new 0 0 792 792;" xml:space="preserve">
<g fill="none" stroke="black" stroke-width="15">
......
......
.......
</g>
</svg>
After
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="792px" height="792px" viewBox="0 0 792 792" style="enable-background:new 0 0 792 792;" xml:space="preserve">
<g fill="none" stroke="black" stroke-width="15">
......
......
.......
</g>
</svg>
I exported my svg from Photoshop CC initially and had to manually add
version="1.1" into the <svg> tag
to get it showing on chrome.
Content type in the HTTP header from the server was the problem for me. I have a node.js server, added:
if( pageName.substring(pageName.lastIndexOf('.')) == '.svg' ) {
res.writeHead(200, { "Content-Type": "image/svg+xml" });
}
pageName is my local variable for what is requested.
My guess is this is a common problem! Am using the current version of Chrome (Mar 2020).
For me setting width / height to the img worked.
<asp:Image runat="server" ID="Icon" Style="max-width: 50px; max-height: 50px; position: relative;" />
I tried most of the solutions above, but didn't worked for me.
I used a svg sanitizr https://svg.enshrined.co.uk/ which worked.
I had a similar issue I think trying to set Sharepoint Icon to SVG and the file did not load properly (while Png did).
See thread: file-format-can-an-svg-file-be-used-as-a-site-icon-in-sharepoint-online
The reason for the issue is that the height and width flags are not set in the tag.
For instance, setting this works
I was able to fix the issue by:
Open SVG in a text editor (e.g. Notepad)
Include in the first SVG header code Width="80" Height="80" (perhaps can play with optimizing the size)
Save file and upload. IT WORKS!
So the first tag of my SVG looks like this
<svg height="80" width="80" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 114.60458 114.60458">
Had the same problem. If server is configured correctly and .htacces is not the answer, might want to look the svg source you are embedding. Mine were created with text editor, rendered well on Chrome&Safari inside html5 code, once embedded, nothing was visible.
Added correct version, dimensions etc to the svg code and works like a charm.
Also, all styles inline.
Ie
<svg version="1.1" baseProfile="full" width="24" height="24" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" rx="2" ry="2" width="24" height="24" style="fill:#fbc800;width:24px;height:24px;" />
</svg>
Be careful that you don't have transition css property for you svg images
I don't now why, but if you make: "transition: all ease 0.3s" for svg image on Chrome the images do not appear
e.g:
* {
transition: all ease 0.3s
}
Chrome do not render svg.
Remove any transition css property and try again
On problems try to open the images first with a program that is capable to read svg-images.
If that fails, then the svg-image is somehow corrupted.
I had that case and copied the svg-paths in a new svg-image and adjusted all details of the svg-tags.
I never tested the reason that it was not rendering but suppose that some invisible special signs caused the render-error. Getting sometimes files edited on Mac I had this issue in other context already.
I was having the same issue with an SVG image included via the IMG tag. It turned out for me that Chrome didn't like there being a blank line directly at the top of the file.
I removed the blank line and my SVG immediately started rendering.
I make sure that I add the Style of the Image. It worked for me
style= "width:320; height:240"
Lighttpd
My problem was that was missing a mime handler for svg files in lighttpd configuration file. Adding these to your lighttpd.conf could solve your problem:
mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".svg" => "image/svg+xml",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".spec" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
".odt" => "application/vnd.oasis.opendocument.text",
".ods" => "application/vnd.oasis.opendocument.spreadsheet",
".odp" => "application/vnd.oasis.opendocument.presentation",
".odg" => "application/vnd.oasis.opendocument.graphics",
".odc" => "application/vnd.oasis.opendocument.chart",
".odf" => "application/vnd.oasis.opendocument.formula",
".odi" => "application/vnd.oasis.opendocument.image",
".odm" => "application/vnd.oasis.opendocument.text-master",
".ott" => "application/vnd.oasis.opendocument.text-template",
".ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
".otp" => "application/vnd.oasis.opendocument.presentation-template",
".otg" => "application/vnd.oasis.opendocument.graphics-template",
".otc" => "application/vnd.oasis.opendocument.chart-template",
".otf" => "application/vnd.oasis.opendocument.formula-template",
".oti" => "application/vnd.oasis.opendocument.image-template",
".oth" => "application/vnd.oasis.opendocument.text-web",
# make the default mime type application/octet-stream.
"" => "application/octet-stream",
)
References
Alternative of AddType in lighthttpd
In my case it was not loading svg due to image tag's id containing _ (underscore) in it so I removed that from
<image id="image0_1166:0000"> to <image id="image0"> and it worked. And don't forget to remove the same here
<use xlink:href="#image0">