<image>
CSS
data type
represents a two-dimensional image.
<image>
data type can be represented with any of the following:
<url>
data type
<gradient>
data type
element()
function
image()
function
cross-fade()
函数。
image-set()
函数。
CSS can handle the following kinds of images:
CSS determines an object's
concrete size
using (1) its
intrinsic dimensions
; (2) its
specified size
, defined by CSS properties like
width
,
height
,或
background-size
; and (3) its
default size
, determined by the kind of property the image is used with:
| Kind of Object (CSS Property) | Default object size |
|---|---|
background-image
|
The size of the element's background positioning area |
list-style-image
|
The size of a
1em
character
|
border-image-source
|
The size of the element's border image area |
cursor
|
The browser-defined size matching the usual cursor size on the client's system |
mask-image
|
? |
shape-outside
|
? |
mask-border-source
|
? |
symbols
for @counter-style
|
At risk feature. If supported, the browser-defined size matching the usual cursor size on the client's system |
content
for a pseudo-element (
::after
/
::before
)
|
A 300px × 150px rectangle |
The concrete object size is calculated using the following algorithm:
Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.
url(test.jpg) /* A <url>, as long as test.jpg is an actual image */
linear-gradient(blue, red) /* A <gradient> */
element(#realid) /* A part of the webpage, referenced with the element() function,
if "realid" is an existing ID on the page */
image(ltr 'arrow.png#xywh=0,0,16,16', red)
/* A section 16x16 section of <url>, starting from the top, left of the original
image as long as arrow.png is a supported image, otherwise a solid
red swatch. If language is rtl, the image will be horizontally flipped. */
cross-fade(20% url(twenty.png), url(eighty.png))
/* cross faded images, with twenty being 20% opaque
and eighty being 80% opaque. */
image-set('test.jpg' 1x, 'test-2x.jpg' 2x)
/* a selection of images with varying resolutions */
nourl.jpg /* An image file must be defined using the url() function. */
url(report.pdf) /* A file pointed to by the url() function must be an image. */
element(#fakeid) /* An element ID must be an existing ID on the page. */
image(z.jpg#xy=0,0) /* The spatial fragment must be written in the format of xywh=#,#,#,# */
image-set('cat.jpg' 1x, 'dog.jpg' 1x) /* every image in an image set must have a different resolutions */
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Images Module Level 4
The definition of '<image>' in that specification. |
工作草案 |
添加
element()
,
image()
,
image-set()
,
conic-gradient()
,
repeating-conic-gradient()
,和
image-resolution
.
|
|
CSS Images Module Level 3
The definition of '<image>' in that specification. |
候选推荐 |
Initial definition. Before this, there was no explicitly defined
<image>
data type. Images could only be defined using the
url()
functional notation.
|
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
<image>
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 10 | Opera 完整支持 2 | Safari 完整支持 1 | WebView Android 完整支持 1 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 11 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
cross-fade()
|
Chrome
完整支持
17
Prefixed
注意事项
|
Edge
完整支持
79
Prefixed
注意事项
|
Firefox 不支持 No | IE 不支持 No |
Opera
完整支持
15
Prefixed
注意事项
|
Safari
完整支持
10
注意事项
|
WebView Android
完整支持
≤37
Prefixed
注意事项
|
Chrome Android
完整支持
18
Prefixed
注意事项
|
Firefox Android 不支持 No |
Opera Android
完整支持
14
Prefixed
注意事项
|
Safari iOS
完整支持
9.3
注意事项
|
Samsung Internet Android
完整支持
1.0
Prefixed
注意事项
|
element()
Experimental
|
Chrome 不支持 No | Edge 不支持 No |
Firefox
完整支持
57
Prefixed
|
IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No |
Firefox Android
完整支持
60
Prefixed
|
Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
<gradient>
|
Chrome 完整支持 26 |
Edge
完整支持
12
Prefixed
|
Firefox
完整支持
3.6
注意事项
|
IE
完整支持
10
Prefixed
|
Opera
完整支持
12.1
|
Safari 完整支持 6.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
4
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS 完整支持 7 | Samsung Internet Android 完整支持 1.5 |
image()
|
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 |
image-set()
|
Chrome
完整支持
21
Prefixed
|
Edge
完整支持
79
Prefixed
|
Firefox
不支持
No
注意事项
|
IE 不支持 No |
Opera
完整支持
15
Prefixed
|
Safari
部分支持
6
Prefixed
注意事项
|
WebView Android
完整支持
4.4
Prefixed
|
Chrome Android
完整支持
25
Prefixed
|
Firefox Android
不支持
No
注意事项
|
Opera Android
完整支持
14
Prefixed
|
Safari iOS
部分支持
6
Prefixed
注意事项
|
Samsung Internet Android
完整支持
1.5
Prefixed
|
paint()
|
Chrome 完整支持 65 | Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No | Opera 完整支持 52 | Safari 不支持 No | WebView Android 完整支持 65 | Chrome Android 完整支持 65 | Firefox Android 不支持 No | Opera Android 完整支持 47 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 9.2 |
完整支持
部分支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
要求使用供应商前缀或不同名称。
<angle-percentage>
<angle>
<basic-shape>
<blend-mode>
<custom-ident>
<dimension>
<frequency-percentage>
<frequency>
<gradient>
<image>
<integer>
<length-percentage>
<length>
<number>
<percentage>
<ratio>
<resolution>
<shape>
<string>
<time-percentage>
<time>
<transform-function>
<url>
color
flex
ident
image-orientation
image-rendering
object-fit
object-position
position