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;
One or more
<position>
values, separated by commas.
<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.
| 初始值 |
center
|
|---|---|
| 适用于 |
all elements; In SVG, it applies to container elements excluding the
defs
element and all graphics elements
|
| 继承 | no |
| 百分比 |
refer to size of mask painting area minus size of mask layer image (see the text for
background-position
)
|
| 计算值 | Consists 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. |
| 动画类型 | repeatable list of simple list of length, percentage, or calc |
<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>
#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;
}
<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>
var maskPosition = document.getElementById("maskPosition");
maskPosition.addEventListener("change", function (evt) {
document.getElementById("masked").style.maskPosition = evt.target.value;
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Masking Module Level 1
The definition of 'mask-position' in that specification. |
候选推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mask-position
|
Chrome
完整支持
1
Prefixed
|
Edge 完整支持 18 |
Firefox
完整支持
53
|
IE 不支持 No |
Opera
完整支持
15
Prefixed
|
Safari
完整支持
3.2
Prefixed
|
WebView Android
完整支持
2
Prefixed
|
Chrome Android
完整支持
18
Prefixed
|
Firefox Android
完整支持
53
|
Opera Android
完整支持
14
Prefixed
|
Safari iOS
完整支持
3.2
Prefixed
|
Samsung Internet Android
完整支持
1.0
Prefixed
|
| Support for three-value syntax of position |
Chrome
不支持
1 — 68
Prefixed
|
Edge 不支持 18 — 79 |
Firefox
不支持
53 — 70
|
IE 不支持 No |
Opera
不支持
15 — 55
Prefixed
|
Safari
完整支持
3.2
Prefixed
|
WebView Android
不支持
2 — 68
Prefixed
|
Chrome Android
不支持
18 — 68
Prefixed
|
Firefox Android
完整支持
53
|
Opera Android
不支持
14 — 48
Prefixed
|
Safari iOS
完整支持
3.2
Prefixed
|
Samsung Internet Android
不支持
1.0 — 10.0
Prefixed
|
完整支持
不支持
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。