7

I am working on a site where I am using a SVG fragments file and loading in particular SVGs via CSS background images.

I also have a PNG fallback and I'm using the below as as basis for the work: https://css-tricks.com/a-complete-guide-to-svg-fallbacks/#fallback-svg-css-background-image

EXAMPLE

.ico-arrow-right {
  background: url(ico-arrow-right.png);
  background: url(sprite-collection.svg#arrowright),
    linear-gradient(transparent, transparent);
}

The problem is, it appears to work fine on most browsers but in Safari on desktop and IOS browsers, the SVG doesn't appear and just shows a blank space. Looking into this, it seems Safari/webkit on devices, doesn't like SVG fragment sprites when using them with CSS background images.

Is there any solution/work around for this? I still want to use CSS background image to pull in the PNG/SVG, and don't want to revert to using individual SVG files as there is over 60 svgs and I don't want that all those server requests!

Thanks all

2

1 Answer 1

0

Add a "content-type" header for SVG files in your server, for example in apache adding this to your .htaccess file:

AddType image/svg+xml .svg .svgz

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.