border-image
CSS
property draws an image around a given element. It replaces the element's regular
border
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
注意:
You should specify a separate
border-style
in case the border image fails to load. Indeed, this is required according to the specification, although not all browsers implement this requirement.
此特性是下列 CSS 特性的简写:
/* source | slice */
border-image: linear-gradient(red, blue) 27;
/* source | slice | repeat */
border-image: url("/images/border.png") 27 space;
/* source | slice | width */
border-image: linear-gradient(red, blue) 27 / 35px;
/* source | slice | width | outset | repeat */
border-image: url("/images/border.png") 27 23 / 50px 30px / 1rem round space;
border-image
property may be specified with anywhere from one to five of the values listed below.
注意:
若
computed value
of
border-image-source
is
none
, or if the image cannot be displayed, the
border-style
will be displayed instead.
<'border-image-source'>
border-image-source
.
<'border-image-slice'>
border-image-slice
.
<'border-image-width'>
border-image-width
.
<'border-image-outset'>
border-image-outset
.
<'border-image-repeat'>
border-image-repeat
.
Assistive technology cannot parse border images. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.
| 初始值 |
as each of the properties of the shorthand:
|
|---|---|
| 适用于 |
all elements, except internal table elements when
border-collapse
is
collapse
. It also applies to
::first-letter
.
|
| 继承 | no |
| 百分比 |
as each of the properties of the shorthand:
|
| 计算值 |
as each of the properties of the shorthand:
|
| 动画类型 | discrete |
<'border-image-source'> || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? || <'border-image-repeat'>
In this example, we will apply a diamond pattern to an element's borders. The source for the border image is a ".png" file of 81 by 81 pixels, with three diamonds going vertically and horizontally:
<div id="bitmap">This element is surrounded by a bitmap-based border image!</div>
To match the size of a single diamond, we will use a value of 81 divided by 3, or
27
, for slicing the image into corner and edge regions. To center the border image on the edge of the element's background, we will make the outset values equal to half of the width values. Finally, a repeat value of
round
will make the border slices fit evenly, i.e., without clipping or gaps.
#bitmap {
width: 200px;
background-color: #ffa;
border: 36px solid orange;
margin: 30px;
padding: 10px;
border-image:
url("https://mdn.mozillademos.org/files/4127/border.png") /* source */
27 / /* slice */
36px 28px 18px 8px / /* width */
18px 14px 9px 4px /* outset */
round; /* repeat */
}
<div id="gradient">This element is surrounded by a gradient-based border image!</div>
#gradient {
width: 200px;
border: 30px solid;
border-image: repeating-linear-gradient(45deg, #f33, #3bf, #f33 30px) 60;
padding: 20px;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Backgrounds and Borders Module Level 3
The definition of 'border-image' in that specification. |
候选推荐 | 初始定义 |
| 初始值 |
as each of the properties of the shorthand:
|
|---|---|
| 适用于 |
all elements, except internal table elements when
border-collapse
is
collapse
. It also applies to
::first-letter
.
|
| 继承 | no |
| 百分比 |
as each of the properties of the shorthand:
|
| 计算值 |
as each of the properties of the shorthand:
|
| 动画类型 | discrete |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
border-image
|
Chrome 完整支持 16 | Edge 完整支持 12 |
Firefox
完整支持
15
注意事项
|
IE 完整支持 11 |
Opera
完整支持
11
|
Safari 完整支持 6 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 |
Firefox Android
完整支持
15
注意事项
|
Opera Android
完整支持
11
|
Safari iOS 完整支持 6 | Samsung Internet Android 完整支持 1.0 |
fill
|
Chrome 完整支持 16 | Edge 完整支持 12 | Firefox 完整支持 15 | IE 完整支持 11 | Opera 完整支持 15 | Safari 完整支持 6 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 15 | Opera Android 完整支持 14 | Safari iOS 完整支持 6 | Samsung Internet Android 完整支持 1.0 |
<gradient>
|
Chrome 完整支持 7 | Edge 完整支持 12 | Firefox 完整支持 29 | IE 完整支持 11 | Opera 完整支持 15 | Safari 完整支持 4 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 29 | Opera Android 完整支持 14 | Safari iOS 完整支持 3.2 | Samsung Internet Android 完整支持 1.0 |
optional
<border-image-slice>
|
Chrome 完整支持 16 | Edge 完整支持 12 | Firefox 完整支持 15 | IE 完整支持 11 | Opera 完整支持 15 | Safari 完整支持 6 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 15 | Opera Android 完整支持 14 | Safari iOS 完整支持 6 | Samsung Internet Android 完整支持 1.0 |
完整支持
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
border
outline
box-shadow
background-image
url()
function
conic-gradient()
,
linear-gradient()
,
repeating-linear-gradient()
,
radial-gradient()
,
repeating-radial-gradient()
background
background-attachment
background-clip
background-color
background-image
background-origin
background-position
background-position-x
background-position-y
background-repeat
background-size
border
border-bottom
border-bottom-color
border-bottom-left-radius
border-bottom-right-radius
border-bottom-style
border-bottom-width
border-color
border-image
border-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
border-left
border-left-color
border-left-style
border-left-width
border-radius
border-right
border-right-color
border-right-style
border-right-width
border-style
border-top
border-top-color
border-top-left-radius
border-top-right-radius
border-top-style
border-top-width
border-width
box-shadow