我正在尝试在 mozilla 中运行 svg 剪辑路径,但它不起作用。
.mask-1 {
-webkit-clip-path: polygon(0% 0%, 58% 0%, 39% 81.8%, 0% 81.8%);
clip-path: polygon(0% 0%, 58% 0%, 39% 81.8%, 0% 81.8%);
}
它完美地在铬中工作。谁能帮助我使用 Mozilla 和其他浏览器?
您可以在 Firefox 中使用内联 SVG(如下面的代码所示),其中您的分数是百分比 / 100。由于该属性clipPathUnits
,掩码将是响应式的。
<svg width="0" height="0">
<defs>
<clipPath id="clip-shape" clipPathUnits="objectBoundingBox">
<polygon points="0 0, 0.58 0, 0.39 0.818, 0 0.818" />
</clipPath>
</defs>
</svg>
参考svg之类
.mask-1 {
-webkit-clip-path: polygon(0% 0%, 58% 0%, 39% 81.8%, 0% 81.8%);
clip-path: polygon(0% 0%, 58% 0%, 39% 81.8%, 0% 81.8%);
-webkit-clip-path: url("#clip-shape");
clip-path: url("#clip-shape");
}
我为此苦苦挣扎,因为我的 svg 是动态添加到页面中的。通过js延迟(或页面加载)应用clip-path css-property解决了我在FF中的问题。
据我所知,IE 中没有任何支持。
我也为此苦苦挣扎。我所涵盖的内容与上述答案相似,但我发现的一个解决方案是使用 Style 标签添加 CSS 内联。这很丑陋,但至少有效。
<div class="clip-this" style="background:red; height: 200px; width: 200px;"></div>
<!-- this lets Firefox display the angle -->
<svg class="clip-svg">
<defs>
<clipPath id="swipe__clip-path" clipPathUnits="objectBoundingBox">
<polygon points="0.404 0, 1 0, 1 1, 0 1" />
</clipPath>
</defs>
</svg>
<style>
.clip-this {
clip-path: polygon(40.4% 0, 100% 0, 100% 100%, 0 100%);
clip-path: url("#swipe__clip-path");
}
</style>
除了@atomictom 的回答,我发现如果您将 div 的类更改为 id,那么您就不必内联 CSS
body{
background: lightgreen;
}
#clip-this {
background:red;
height: 200px;
width: 200px;
clip-path: polygon(40.4% 0, 100% 0, 100% 100%, 0 100%);
clip-path: url("#swipe__clip-path");
}
<div id="clip-this"></div>
<!-- this lets Firefox display the angle -->
<svg class="clip-svg">
<defs>
<clipPath id="swipe__clip-path" clipPathUnits="objectBoundingBox">
<polygon points="0.404 0, 1 0, 1 1, 0 1" />
</clipPath>
</defs>
</svg>