<mask> - SVG: Scalable Vector Graphics 编辑

The <mask> element defines an alpha mask for compositing the current object into the background. A mask is used/referenced using the mask property.

html,body,svg { height:100% }
<svg viewBox="-10 -10 120 120">
  <mask id="myMask">
    <!-- Everything under a white pixel will be visible -->
    <rect x="0" y="0" width="100" height="100" fill="white" />

    <!-- Everything under a black pixel will be invisible -->
    <path d="M10,35 A20,20,0,0,1,50,35 A20,20,0,0,1,90,35 Q90,65,50,95 Q10,65,10,35 Z" fill="black" />
  </mask>

  <polygon points="-10,110 110,110 110,-10" fill="orange" />

  <!-- with this mask applied, we "punch" a heart shape hole into the circle -->
  <circle cx="50" cy="50" r="50" mask="url(#myMask)" />
</svg>

Attributes

height
This attribute defines the height of the masking area.
Value type: <length> ; Default value: 120%; Animatable: yes
maskContentUnits
This attribute defines the coordinate system for the contents of the <mask>.
Value typeuserSpaceOnUse|objectBoundingBox ; Default value: userSpaceOnUse; Animatable: yes
maskUnits
This attribute defines the coordinate system for attributes x, y, width and height on the <mask>.
Value typeuserSpaceOnUse|objectBoundingBox ; Default value: objectBoundingBox; Animatable: yes
x
This attribute defines the x-axis coordinate of the top-left corner of the masking area.
Value type: <coordinate> ; Default value: -10%; Animatable: yes
y
This attribute defines the y-axis coordinate of the top-left corner of the masking area.
Value type: <coordinate> ; Default value: -10%; Animatable: yes
width
This attribute defines the width of the masking area.
Value type: <length> ; Default value: 120%; Animatable: yes

Global attributes

Core Attributes
Most notably: id
Styling Attributes
class, style
Conditional Processing Attributes
Most notably: requiredExtensions, systemLanguage
Presentation Attributes
Most notably: clip-path, clip-rule, color, display, fill, fill-opacity, fill-rule, filter, mask, opacity, shape-rendering, stroke, stroke-dasharray, stroke-dashoffset, stroke-linecap, stroke-linejoin, stroke-miterlimit, stroke-opacity, stroke-width, transform, vector-effect, visibility

Usage notes

CategoriesContainer element
Permitted contentAny number of the following elements, in any order:
Animation elements
Descriptive elements
Shape elements
Structural elements
Gradient elements
<a>, <altGlyphDef>, <clipPath>, <color-profile>, <cursor>, <filter>, <font>, <font-face>, <foreignObject>, <image>, <marker>, <mask>, <pattern>, <script>, <style>, <switch>, <text>, <view>

Specifications

SpecificationStatusComment
CSS Masking Module Level 1
The definition of '<mask>' in that specification.
Candidate Recommendation 
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
The definition of '<mask>' in that specification.
RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:100 次

字数:11414

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文