Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clipping path in SVG not working in Safari

I've created a simple polygon in Illustrator and then created a clipping path (mask) in front of an image. I've exported it as an SVG file, and it renders perfectly in Chrome and Safari.

However, when I create an HTML file using the SVG data, it renders perfectly in Chrome but not Safari 6.0.2.

Not quite sure what I might be doing wrong; I've created examples of the SVG example (personal site) and the HTML (example on jsfiddle).

like image 238
Rob Erskine Avatar asked Dec 20 '22 11:12

Rob Erskine


2 Answers

You must be running into a bug in Safari, instead of using use to apply the mask, just use the actual polygon element:

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="700px" height="700px" viewBox="0 0 700 700" style="enable-background:new 0 0 700 700;" xml:space="preserve">
  <g>  

    <clipPath id="SVGID_2_">
      <polygon id="SVGID_1_" points="576.35,444.245 670.595,350 576.349,255.754 576.349,123.651 444.246,123.651 350,29.405 255.755,123.651 122.96,123.651 122.96,256.446 29.405,350.001 122.96,443.555 122.96,577.041 256.446,577.041 350,670.595 443.554,577.041 576.35,577.041"/>
    </clipPath>

    <g id="LwhyVN.tif" style="clip-path:url(#SVGID_2_);">
      <image style="overflow:visible;" width="1024" height="768" id="Layer_0_1_" xlink:href="http://fc05.deviantart.net/fs13/f/2007/071/9/e/Japanese_shiba_inu__shiba_dog__by_MogamiJ.jpg"  transform="matrix(0.8418 0 0 0.8418 27.5078 37.498)"></image>
    </g>

  </g>
</svg>

This works for me in Safari 6.

like image 185
methodofaction Avatar answered Jan 02 '23 09:01

methodofaction


Also watch out if you have a base tag in your html as safari apparently adds the base to the id selector.

like image 28
velop Avatar answered Jan 02 '23 10:01

velop