非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
-moz-context-properties
property can be used within privileged contexts in Firefox to share the values of specified properties of the element with a child SVG image.
If you reference an SVG image in a webpage (such as with the
<img>
element or as a background image), the SVG image can coordinate with the embedding element (its context) to have the image adopt property values set on the embedding element. To do this the embedding element needs to list the properties that are to be made available to the image by listing them as values of the
-moz-context-properties
property, and the image needs to opt in to using those properties by using values such as the
context-fill
值。
/* Keyword values */ -moz-context-properties: fill; -moz-context-properties: fill, stroke; /* Global values */ -moz-context-properties: inherit; -moz-context-properties: initial; -moz-context-properties: unset;
fill
fill
value set on the image to the embedded SVG.
stroke
stroke
value set on the image to the embedded SVG.
fill-opacity
fill-opacity
value set on the image to the embedded SVG.
stroke-opacity
stoke-opacity
value set on the image to the embedded SVG.
| 初始值 |
none
|
|---|---|
| 适用于 |
Any element that can have an image applied to it, for example as a
background-image
,
border-image
,或
list-style-image
.
|
| 继承 | yes |
| 计算值 | 如指定 |
| 动画类型 | discrete |
none | [ fill | fill-opacity | stroke | stroke-opacity ]#
In this example we have a simple SVG embedded using an
<img>
元素。
You first need to specify on the embedding element the properties whose values you wish to expose to the embedded SVG, using the
-moz-context-properties
property. For example:
.img1 {
width: 100px;
height: 100px;
-moz-context-properties: fill, stroke;
fill: lime;
stroke: purple;
}
Now that you've done this, the SVG image can use the values of the
fill
and
stroke
properties, for example:
<img class="img1" src="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'>
<rect width='100%' height='100%' stroke-width='30px'
fill='context-fill red' stroke='context-stroke' fill-opacity='0.5'/></svg>">
Here we've set the image
src
to a data URI containing a simple SVG image; the
<rect>
inside has been made to take its
fill
and
stroke
values from the
fill
and
stroke
set on the
<img>
element by giving them the
context-fill
/
context-stroke
keywords in their values, along with a fallback color for the fill (red) which will be used in the case that the SVG is loaded standalone in a top-level window (where it will have no context element to provide context values). Note that if a color is set directly on the SVG, but then the context color is also specified, the context color overrides the direct color.
注意 : You can find a working example on Github .
Not part of any standard.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
-moz-context-properties
Experimental
非标
|
Chrome 不支持 No | Edge 不支持 No |
Firefox
完整支持
55
注意事项
Disabled
|
IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No |
Firefox Android
完整支持
55
注意事项
Disabled
|
Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
完整支持
不支持
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
见实现注意事项。
用户必须明确启用此特征。
-moz-context-properties
-moz-float-edge
-moz-force-broken-image-icon
-moz-image-region
-moz-orient
-moz-outline-radius
-moz-outline-radius-bottomleft
-moz-outline-radius-bottomright
-moz-outline-radius-topleft
-moz-outline-radius-topright
-moz-user-focus
-moz-user-input
box-align
box-direction
box-flex
box-flex-group
box-lines
box-ordinal-group
box-orient
box-pack