大网数据广告活动
Web 标准与前端开发

clip-rule

· 52CE 我爱测

The `clip-rule` attribute only applies to graphics elements that are contained within a clipPath element. The `clip-rule` attribute basically works as the fill-rule attribute, except that it applies to clipPath definitions.

The clip-rule attribute only applies to graphics elements that are contained within a clipPath element. The clip-rule attribute basically works as the fill-rule attribute, except that it applies to clipPath definitions.

[!NOTE] As a presentation attribute, clip-rule also has a CSS property counterpart: clip-rule. When both are specified, the CSS property takes priority.

The following fragment of code will cause an evenodd clipping rule to be applied to the clipping path because clip-rule is specified on the path element that defines the clipping shape:

<g>
  <clipPath id="MyClip">
    <path d="..." clip-rule="evenodd" />
  </clipPath>
  <rect clip-path="url(#MyClip)" ... />
</g>

whereas the following fragment of code will not cause an evenodd clipping rule to be applied because the clip-rule is specified on the referencing element, not on the object defining the clipping shape:

<g>
  <clipPath id="MyClip">
    <path d="..." />
  </clipPath>
  <rect clip-path="url(#MyClip)" clip-rule="evenodd" ... />
</g>

Elements

The following elements can use the clip-rule attribute, but only if they are inside a clipPath element.

Example

<svg width="100" viewBox="0 0 100 90" xmlns="http://www.w3.org/2000/svg">
  
  <defs>
    <path d="M50,0 21,90 98,35 2,35 79,90z" id="star" />
  </defs>

  
  <clipPath id="emptyStar">
    <use href="#star" clip-rule="evenodd" />
  </clipPath>
  <rect clip-path="url(#emptyStar)" width="50" height="90" fill="blue" />

  
  <clipPath id="filledStar">
    <use href="#star" clip-rule="nonzero" />
  </clipPath>
  <rect clip-path="url(#filledStar)" width="50" height="90" x="50" fill="red" />
</svg>

Example

Usage notes

<table class="properties"> <tbody> <tr> <th scope="row">Value</th> <td>nonzero | evenodd | inherit</td> </tr> <tr> <th scope="row">Default value</th> <td>nonzero</td> </tr> <tr> <th scope="row">Animatable</th> <td>Yes</td> </tr> </tbody> </table>

  • nonzero
    • : See description of fill-rule property.
  • evenodd
    • : See description of fill-rule property.

Specifications

Browser compatibility

See also

  • clipPath
  • CSS clip-rule property

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。