简体   繁体   English

为什么在clipPath元素中时svg路径会更改大小?

[英]Why does the svg path change size when inside a clipPath element?

I have a svg path that I am trying to use as a clip mask. 我有一个svg路径,试图将其用作剪贴蒙版。 When I add the svg path to an svg element, its size lines up with the image I want to clip. 当我将svg路径添加到svg元素时,其大小与我要裁剪的图像对齐。 However, If I copy and paste the same path into a clipPath element, it changes size. 但是,如果我将同一路径复制并粘贴到clipPath元素中,它将更改大小。 In the code below you can see that the same path is used to draw an svg and in a clipPath. 在下面的代码中,您可以看到在clipPath中使用相同的路径绘制svg。 The drawn path is the correct size, however the clipPath is larger. 绘制的路径是正确的大小,但是clipPath较大。

  <svg id="clip-svg" viewBox="0 0 374 518">  
    <path d="M374,0l-41.7,492.3c0,0-61.6,25.7-143.3,25.7S41.7,492.3,41.7,492.3L0,0C12,16.1,366.2,17.7,374,0z"/>
    <defs>
      <clipPath id="clip-path">
        <path d="M374,0l-41.7,492.3c0,0-61.6,25.7-143.3,25.7S41.7,492.3,41.7,492.3L0,0C12,16.1,366.2,17.7,374,0z"/>
      </clipPath>
    </defs>
  </svg>

Why is the path changing size when placed in the clipPath? 为什么放置在clipPath中时路径会改变大小?

You don't say, but I assume you are clipping an HTML element? 您没有说,但我认为您正在剪辑HTML元素?

When a clipPath is used outside of the SVG, it is not longer subject to the scaling that happens due to the viewBox . 当在SVG之外使用clipPath时,由于viewBox ,它不再受制于缩放。 So it will be used, as defined, at 1:1 scale. 因此,它将按定义以1:1的比例使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM