gpt4 book ai didi

svg - 如何使用带有符号和 的 SVG clipPath

转载 作者:行者123 更新时间:2023-12-02 03:17:13 26 4
gpt4 key购买 nike

我有以下有效的 SVG:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500">
<defs>
<symbol id="triangle" class="triangle" viewBox="0 0 100 100" preserveAspectRatio="none">
<polygon points="0,100 50,0 100,100" stroke="none" />
</symbol>

<symbol id="rect" viewBox="0 0 100 100" preserveAspectRatio="none">
<rect width='100' height='100' stroke="none"/>
</symbol>
</defs>

<use xlink:href="#rect" width="300" height="300" x="100" y="100"/>
<use xlink:href="#triangle" width="120" height="150" x="180" y="100" fill="white" transform="rotate(180, 250, 175)"/>
</svg>

但是当我尝试将其变成 clipPath 时它变成空白。想知道如何获得 clipPath上类。这是我尝试过的。

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500">
<defs>
<symbol id="triangle" class="triangle" viewBox="0 0 100 100" preserveAspectRatio="none">
<polygon points="0,100 50,0 100,100" stroke="none" />
</symbol>

<symbol id="rect" viewBox="0 0 100 100" preserveAspectRatio="none">
<rect width='100' height='100' stroke="none"/>
</symbol>

<clipPath id="clip">
<use xlink:href="#triangle" width="120" height="150" x="180" y="100" fill="white" transform="rotate(180, 250, 175)"/>
</clipPath>
</defs>

<use xlink:href="#rect" width="300" height="300" x="100" y="100" clip-path="url(#clip)"/>
</svg>

目标是让它从矩形中切出三角形,同时使用 <use>功能。稍后我可能会有一个更复杂的剪切路径示例,这只是演示问题。

最佳答案

来自 SVG 规范:

https://www.w3.org/TR/SVG11/single-page.html#masking-EstablishingANewClippingPath

A ‘clipPath’ element can contain ‘path’ elements, ‘text’ elements, basic shapes (such as ‘circle’) or a ‘use’ element. If a ‘use’ element is a child of a ‘clipPath’ element, it must directly reference ‘path’, ‘text’ or basic shape elements. Indirect references are an error

关于svg - 如何使用带有符号和 <use> 的 SVG clipPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55782439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com