mask-position - CSS: Cascading Style Sheets 编辑

The mask-position CSS property sets the initial position, relative to the mask position layer set by mask-origin, for each defined mask image.

/* Keyword values */
mask-position: top;
mask-position: bottom;
mask-position: left;
mask-position: right;
mask-position: center;

/* <position> values */
mask-position: 25% 75%;
mask-position: 0px 0px;
mask-position: 10% 8em;

/* Multiple values */
mask-position: top right;
mask-position: 1rem 1rem, center;

/* Global values */
mask-position: inherit;
mask-position: initial;
mask-position: unset;

Syntax

One or more <position> values, separated by commas.

Values

<position>
One to four values representing a 2D position regarding the edges of the element's box. Relative or absolute offsets can be given. Note that the position can be set outside of the element's box.

Formal definition

Initial valuecenter
Applies toall elements; In SVG, it applies to container elements excluding the defs element and all graphics elements
Inheritedno
Percentagesrefer to size of mask painting area minus size of mask layer image (see the text for background-position)
Computed valueConsists of two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <length>), otherwise as a percentage.
Animation typerepeatable list of simple list of length, percentage, or calc

Formal syntax

<position>#

where
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]

where
<length-percentage> = <length> | <percentage>

Examples

Setting mask position

CSS

#wrapper {
  border: 1px solid black;
  width: 250px;
  height: 250px;
}

#masked {
  width: 250px;
  height: 250px;
  background: blue linear-gradient(red, blue);
  mask-image: url(https://mdn.mozillademos.org/files/12676/star.svg);
  mask-repeat: no-repeat;
  mask-position: top right; /* Can be changed in the live sample */
  margin-bottom: 10px;
}

HTML

<div id="wrapper">
  <div id="masked">
  </div>
</div>
<select id="maskPosition">
  <option value="top">top</option>
  <option value="center">center</option>
  <option value="bottom">bottom</option>
  <option value="top right" selected>top right</option>
  <option value="center center">center center</option>
  <option value="bottom left">bottom left</option>
  <option value="10px 20px">10px 20px</option>
  <option value="60% 20%">60% 20%</option>
</select>

JavaScript

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

Result

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:73 次

字数:12568

最后编辑:8年前

编辑次数:0 次

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