【发布时间】:2017-01-14 00:03:43
【问题描述】:
我想知道这是否可能。我试图用 svg 和 clipPath 来实现它。 (jsfiddle example)
body { background-color: #e0e0e0;margin: 0px;width: 100%;height: 100%; }
#img-1 { clip-path: url(#clip-shape); }
<div id="image-wrapper" style="overflow: hidden; width: 100%; height: 150px;">
<div style="width: 100%; height: 100%;">
<svg id="image-svg" viewBox="0 0 100 100" height="100%" width="100%" preserveAspectRatio="xMinYMin slice">
<image id="img-1" class="svg-image" width="100%" height="100%" xlink:href="http://25.media.tumblr.com/tumblr_m5nre6cxkQ1qbs7p5o1_r1_500.jpg"></image>
<svg id="svg-defs" viewBox="0 0 100 100" height="100%" width="100%">
<defs>
<clipPath id="clip-shape">
<polygon points="0 0, 40 0, 50 10, 60 0, 100 0, 100 500, 0 500"></polygon>
</clipPath>
</defs>
</svg>
</div>
</div>
但这仍然不是我想要的,我相信还有更优雅和更简单的解决方案。图像应具有底部对齐方式。剪切部分的大小应以像素为单位并透明,以便下面的内容可见。请参阅下面的附图。
【问题讨论】:
-
我认为您最好的方法是使用 photoshop(如paint.NET)并将您的图像保存为 .png。然后将您的图像作为
background-image应用到您的 div。
标签: html css svg background-image