mask-origin - CSS: Cascading Style Sheets 编辑

The 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.

Syntax

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

Values

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 attribute.
content This API has not been standardized.
Same as content-box.
padding This API has not been standardized.
Same as padding-box.
border This API has not been standardized.
Same as border-box.

Formal definition

Initial valueborder-box
Applies toall elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

<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

Examples

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;
});

Result

Specifications

SpecificationStatusComment
CSS Masking Module Level 1
The definition of 'mask-origin' in that specification.
Candidate RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:114 次

字数:9653

最后编辑:7年前

编辑次数:0 次

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