I have been adding svg images to div tags with the background property in css (example: the treehouse logo on this website). I am having a strange issue I don't quite understand. The svg file loads just fine in my local host, but when I upload the files into my server and preview the site remotely, the svg image doesn't load and the browser doesn't recognize it, as if the file wasn't there. Am I forgetting to add something to the page so it loads properly?
Paulie's example gets served with header Content-Type:image/svg+xml
Yours gets served with header Content-Type:text/plain
I think that could be the problem (not sure), Google for how to change the content-type for svg in the response header (because I don't know how, probably some .htaccess setting if you're using Apache).
Ok it works now! I don't quite understand the logic of the solution tho... In order for it to work, I need to add the .htaccess files with the AddType lines in the same directory where the svg images live. That in return will throw that 500 server error that CrocoDillon mentioned. If I reload the URL, delete the .htaccess file, and reload the URL one more time, it will work.
Hi everyone,
I have been adding svg images to div tags with the background property in css (example: the treehouse logo on this website). I am having a strange issue I don't quite understand. The svg file loads just fine in my local host, but when I upload the files into my server and preview the site remotely, the svg image doesn't load and the browser doesn't recognize it, as if the file wasn't there. Am I forgetting to add something to the page so it loads properly?
Help on this would be super awesome.
Thanks!
What are you putting as the URL to the image? We need the code.
Hi sorry I should've added the example from the start. Please refer to http://codepen.io/anon/pen/cgobp to see the issue I'm running into.
Simple answer....your svg image isn't an image...it's an xml file. with an SVG extension..I think that makes a difference but I'm no expert.
http://www.miguelzuleta.com/temp/1/ii/square.svg
http://codepen.io/Paulie-D/pen/Knejp
Paulie's example gets served with header Content-Type:image/svg+xml
Yours gets served with header Content-Type:text/plain
I think that could be the problem (not sure), Google for how to change the content-type for svg in the response header (because I don't know how, probably some .htaccess setting if you're using Apache).
Paulie and Croco,
thanks for the advice I ended up learning new tricks from it... it still doesn't work tho... strange... I've tried using:
"AddType image/svg+xml svg AddType image/svg+xml svgz"
&
"Content-Type: image/svg+xml"
as an .htaccess file in the directory where my .svg files live, but nothing...
I'm running out of ideas. Would you think it is my server's problem?
http://www.miguelzuleta.com/temp/1/ii/square.svg
I'm getting an error. Do you have access to your server's error log?
I've Googled some and I think you only need
AddType image/svg+xml svg(and svgz extension if you need it)Ok it works now! I don't quite understand the logic of the solution tho... In order for it to work, I need to add the .htaccess files with the AddType lines in the same directory where the svg images live. That in return will throw that 500 server error that CrocoDillon mentioned. If I reload the URL, delete the .htaccess file, and reload the URL one more time, it will work.
Check it out: http://www.miguelzuleta.com/temp/1/ii/square.svg There isn't an error anymore, and it is loading as an image instead of svg code.
Awesome. Thank you guys for your help!
That's weird, always thought .htaccess gets inherited by sub directories. Anyway it works here too, gj!