SVG Clip-path for Custom Image Cropping
Create a responsive clip path for images using SVG shapes in Webflow.This allows you to create unique shaped images using SVG paths rather than DIVs or similar methods.
Create a responsive clip path for images using SVG shapes in Webflow.This allows you to create unique shaped images using SVG paths rather than DIVs or similar methods.
How to add it
- Create your SVG shape in something like Adobe Illustrator.
- Export your SVG as code. You can go to File -> Export as -> SVG in the dialogue box you have the option to show code which will generate the code that you need.
- Make new path 'relative' - You can do so here (https://yoksel.github.io/relative-clip-path/)
- Create element in Webflow. The clip path is going in a div called svg-clip and then you have to put an image inside to fill the width and height by selecting cover.
- Add an embed code and copy and paste the code, make sure class names are relevant to the copied code.
The code
Javascript
<script>
$(function () {
$( "a[data-clean='remove-http']" ).each(function() {
var clean = $(this).text().replace(/^\/\/|^.*?:(\/\/)?/, '');
$(this).text(clean);
});
});
</script>
CSS
<style>
.svg-clip {
width: 0;
height: 0;
}
img {
width: 50%;
-webkit-clip-path: url(#clip-rip-bottom);
clip-path: url(#clip-rip-bottom);
}
</style>
HTML
<svg height="0" width="0" class="svg-clip">
<defs>
<clipPath id="clip-rip-bottom" clipPathUnits="objectBoundingBox">
<path d="M0.983,0 H0 L0.018,0.997 l0.018,-0.002,0.009,-0.003,0.005,-0.003,0.01,-0.001,0.01,0.002,0.003,0,0.002,-0.001,0.013,0.001,0.003,-0.001,0.007,0.001,0.004,0.002,0.047,0.008,0.003,0,0.001,0,0.018,-0.002,0.002,-0.001,0.004,-0.001,0.008,0.002,0.002,0.001,0.006,0,0.003,-0.001,0.02,0,0.01,-0.002,0.003,-0.001,0.069,-0.011,0.034,0.004,0.009,-0.002,0.001,-0.001,0.031,-0.007,0.004,-0.002,0.001,0,0.022,0.001,0.019,-0.004,0.005,0,0.01,0.003,0,0,0.025,0.007,0.034,0.004,0,0,0.003,-0.001,0.008,-0.002,0.005,0,0.012,0.003,0.015,-0.004,0.011,0,0.012,-0.003,0.001,0,0.002,-0.001,0.009,-0.002,0.002,-0.001,0.005,-0.001,0.007,0,0.008,-0.002,0,0,0.003,-0.002,0,-0.001,0.004,-0.003,0.001,0,0.015,-0.003,0.018,0.003,0.004,-0.001,0.004,-0.003,0.023,-0.007,0.012,-0.001,0.013,0.002,0.026,-0.003,0.003,0,0.003,0,0.002,-0.001,0.016,-0.002,0.016,0,0.008,0.002,0.009,0,0.015,0.004,0.017,-0.001,0.008,0.002,0.018,0.001,0.003,0.001,0.007,0,0.007,-0.001,0,0,0.014,-0.003,0.013,0.001,0.015,-0.005,0.012,0,0.004,0.001,0.035,-0.001,0.001,0,0.003,0,0,0,0.006,0,0.017,0.005,0.012,-0.001,0.004,0,0.004,0.001,0.006,0,0.005,-0.001,0.002,-0.001 L0.983,0 h0" />
</clipPath>
</defs>
</svg>