I've been trying to understand how to apply SVG clip-paths to HTML elements, and have run into some oddities.
Here is the fiddle: http://jsfiddle.net/jakemcgraw/8hr99/
<div id="diamond1" class="diamond">
<div id="clip1">
<div></div>
</div>
</div>
<div id="diamond2" class="diamond">
<div id="clip2">
<div></div>
</div>
</div>
<div id="diamond3" class="diamond">
<div id="clip3">
<div></div>
</div>
</div>
<svg>
<defs>
<clippath id="relative_path">
<polygon points="50% 0, 100% 50%, 50% 100%, 0 50%"></polygon>
</clippath>
</defs>
</svg>
<svg>
<defs>
<clippath id="absolute_path">
<polygon points="100 0, 200 100, 100 200, 0 100"></polygon>
</clippath>
</defs>
</svg>
css:
#clip1 {
-webkit-clip-path: polygon( 50% 0, 100% 50%, 50% 100%, 0 50% );
-moz-clip-path: polygon( 50% 0, 100% 50%, 50% 100%, 0 50% );
-o-clip-path: polygon( 50% 0, 100% 50%, 50% 100%, 0 50% );
clip-path: polygon( 50% 0, 100% 50%, 50% 100%, 0 50% );
}
#clip2 {
-webkit-clip-path: url(#relative_path);
-moz-clip-path: url(#relative_path);
-o-clip-path: url(#relative_path);
clip-path: url(#relative_path);
}
#clip3 {
-webkit-clip-path: url(#absolute_path);
-moz-clip-path: url(#absolute_path);
-o-clip-path: url(#absolute_path);
clip-path: url(#absolute_path);
}
A few things to note:
The inline clip-path css declaration only works with Chrome and Opera.
SVG with relative dimensions (i.e. 50%) doesn't seem to work for any browser at all.
SVG with absolute dimensions only works in Firefox.
Note that the second and third elements disappear completely in Chrome and Opera. Now, take a look at this fiddle: http://jsfiddle.net/jakemcgraw/7S5Lk/
The one works correctly in Firefox, but in Chrome and Opera, the 10px margin has moved the underlying element, but NOT the clip. It appears that the SVG clipPath dimensions are applying to the document as a whole, as opposed to the element in question.
Unsurprisingly, neither of these two fiddles work in IE10. I have seen SVG work in IE10, so perhaps the only problem is the mixing of SVG and HTML? Not sure.
Note as well that neither work in Safari.
Is my implementation wrong? Is there a proper way to mix SVG clip-paths with HTML elements that I'm missing?