【发布时间】:2023-03-12 15:45:01
【问题描述】:
我正在尝试使用内部和外部 SVG 创建一个三角形。
但是由于某种原因它不起作用。
我在这里尝试使用这个工具:http://cssplant.com/clip-path-generator
并获得它的“点”坐标以在我的内部和外部 SVG 上创建一个完美的剪辑三角形,但没有运气。
这是我的 HTML:
<figure class="clip-holder">
<img src="https://www.thesun.co.uk/wp-content/uploads/2016/06/nintchdbpict000244881006.jpg" class="clip-svg-inline" width="200" height="200">
<figcaption>Inline SVG</figcaption>
</figure>
<figure class="clip-holder">
<img src="https://www.thesun.co.uk/wp-content/uploads/2016/06/nintchdbpict000244881006.jpg" width="200" height="200">
<figcaption>External SVG</figcaption>
</figure>
</div>
<svg class="clip-svg">
<defs>
<clipPath id="triangle" clipPathUnits="objectBoundingBox" >
<polygon points="120 263,325 262,222 42"/>
</clipPath>
</defs>
</svg>
这是 CSS:
.clip-holder {
display: inline-block;
padding: 0;
margin: 30px;
}
.clip-css {
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.clip-svg {
width: 0;
height: 0;
margin: 0 auto;
}
.clip-svg-inline {
-webkit-clip-path: url("#triangle");
clip-path: url("#triangle");
}
.clip-svg-external {
-webkit-clip-path: url("https://www.thesun.co.uk/wp-content/uploads/2016/06/nintchdbpict000244881006.jpgt");
clip-path: url("https://www.thesun.co.uk/wp-content/uploads/2016/06/nintchdbpict000244881006.jpg");
}
我犯了什么错误吗?
这是 JSFIDDLE:https://jsfiddle.net/stjtudvj/
(显示 jsfiddle 解决方案以便更好地理解)
【问题讨论】:
-
一个clip-path必须指向一个clipPath元素,指向一个jpeg文件是无效的。 CSS 文件中也没有三角形元素,它在 html 文件中,因此本地 #triangle 引用不会找到它。
-
有什么办法可以解决吗?内部和外部 SVG 的任何分辨率?我真的被罗伯特困住了。
-
将剪辑路径指向一个剪辑路径元素。
-
请给我看看 JSFIDDLE 怎么样?
-
"local #triangle reference won't find it" 什么意思?