mask-origin CSS property sets the origin of a mask.

/* Keyword values */
mask-origin: content-box;
mask-origin: padding-box;
mask-origin: border-box;
mask-origin: margin-box;
mask-origin: fill-box;
mask-origin: stroke-box;
mask-origin: view-box;
/* Multiple values */
mask-origin: padding-box, content-box;
mask-origin: view-box, fill-box, border-box;
/* Non-standard keyword values */
-webkit-mask-origin: content;
-webkit-mask-origin: padding;
-webkit-mask-origin: border;
/* Global values */
mask-origin: inherit;
mask-origin: initial;
mask-origin: unset;
					

For elements rendered as a single box, this property specifies the mask positioning area. In other words, this property specifies the origin position of an image specified by the mask-image CSS property. For elements rendered as multiple boxes, such as inline boxes on several lines or boxes on several pages, it specifies which boxes box-decoration-break operates upon to determine the mask positioning area.

句法

One or more of the keyword values listed below, separated by commas.

content-box

The position is relative to the content box.

padding-box
The position is relative to the padding box. For single boxes 0 0 is the upper left corner of the padding edge, 100% 100% is the lower right corner.
border-box

The position is relative to the border box.

margin-box

The position is relative to the margin box.

fill-box

The position is relative to the object bounding box.

stroke-box

The position is relative to the stroke bounding box.

view-box
Uses the nearest SVG viewport as reference box. If a viewBox attribute is specified for the element creating the SVG viewport, the reference box is positioned at the origin of the coordinate system established by the viewBox attribute and the dimension of the reference box is set to the width and height values of the viewBox 属性。
content
如同 content-box .
padding
如同 padding-box .
border
如同 border-box .

形式定义

初始值 border-box
适用于 all elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
继承 no
计算值 如指定
动画类型 discrete

形式句法

<geometry-box>#

where
<geometry-box> = <shape-box> | fill-box | stroke-box | view-box

where
<shape-box> = <box> | margin-box

where
<box> = border-box | padding-box | content-box

范例

Setting mask origin to border-box

CSS

#masked {
  width: 100px;
  height: 100px;
  margin: 10px;
  border: 10px solid blue;
  background-color: #8cffa0;
  padding: 10px;
  mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg);
  mask-origin: border-box; /* Can be changed in the live sample */
}
					

HTML

<div id="masked">
</div>
<select id="origin">
  <option value="content-box">content-box</option>
  <option value="padding-box">padding-box</option>
  <option value="border-box" selected>border-box</option>
  <option value="margin-box">margin-box</option>
  <option value="fill-box">fill-box</option>
  <option value="stroke-box">stroke-box</option>
  <option value="view-box">view-box</option>
</select>
					

JavaScript

var origin = document.getElementById("origin");
origin.addEventListener("change", function (evt) {
  document.getElementById("masked").style.maskOrigin = evt.target.value;
});
					

结果

规范

规范 状态 注释
CSS Masking Module Level 1
The definition of 'mask-origin' in that specification.
候选推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mask-origin Chrome 完整支持 1 Prefixed 注意事项
完整支持 1 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Edge 完整支持 79 Prefixed 注意事项
完整支持 79 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Firefox 完整支持 53
完整支持 53
不支持 20 — 53 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 15 Prefixed 注意事项
完整支持 15 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Safari 完整支持 4 Prefixed 注意事项
完整支持 4 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
WebView Android 完整支持 2 Prefixed 注意事项
完整支持 2 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Chrome Android 完整支持 18 Prefixed 注意事项
完整支持 18 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Firefox Android 完整支持 53
完整支持 53
不支持 20 — 53 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 完整支持 14 Prefixed 注意事项
完整支持 14 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Safari iOS 完整支持 3.2 Prefixed 注意事项
完整支持 3.2 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
Samsung Internet Android 完整支持 1.0 Prefixed 注意事项
完整支持 1.0 Prefixed 注意事项
Prefixed Implemented with the vendor prefix: -webkit-
注意事项 margin-box value is unsupported.
fill-box Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
Non-standard values content , padding , border 非标 Chrome 完整支持 1 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge 完整支持 79 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox 不支持 No IE 不支持 No Opera 完整支持 15 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari 完整支持 4 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
WebView Android 完整支持 2 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android 完整支持 18 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox Android 不支持 No Opera Android 完整支持 14 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari iOS 完整支持 3.2 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Samsung Internet Android 完整支持 1.0 Prefixed
完整支持 Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
stroke-box Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No
view-box Chrome 不支持 No Edge 不支持 No Firefox 不支持 No IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Masking
  4. 特性
    1. clip
    2. clip-path
    3. mask
    4. mask-border
    5. mask-border-mode
    6. mask-border-outset
    7. mask-border-repeat
    8. mask-border-slice
    9. mask-border-source
    10. mask-border-width
    11. mask-clip
    12. mask-composite
    13. mask-image
    14. mask-mode
    15. mask-origin
    16. mask-position
    17. mask-repeat
    18. mask-size
    19. mask-type

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1