background-origin
CSS
property sets the background's origin: from the border start, inside the border, or inside the padding.
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.
注意,
background-origin
会被忽略当
background-attachment
is
fixed
.
/* Keyword values */ background-origin: border-box; background-origin: padding-box; background-origin: content-box; /* Global values */ background-origin: inherit; background-origin: initial; background-origin: unset;
background-origin
property is specified as one of the keyword values listed below.
border-box
The background is positioned relative to the border box.
padding-box
The background is positioned relative to the padding box.
content-box
The background is positioned relative to the content box.
| 初始值 |
padding-box
|
|---|---|
| 适用于 |
所有元素。它还适用于
::first-letter
and
::first-line
.
|
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | discrete |
<box>#
.example {
border: 10px double;
padding: 10px;
background: url('image.jpg');
background-position: center left;
background-origin: content-box;
}
#example2 {
border: 4px solid black;
padding: 10px;
background: url('image.gif');
background-repeat: no-repeat;
background-origin: border-box;
}
div {
background-image: url('logo.jpg'), url('mainback.png'); /* Applies two images to the background */
background-position: top right, 0px 0px;
background-origin: content-box, padding-box;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Backgrounds and Borders Module Level 3
The definition of 'background-origin' in that specification. |
候选推荐 | 初始定义。 |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
background-origin
|
Chrome
完整支持
1
|
Edge 完整支持 12 |
Firefox
完整支持
4
|
IE
完整支持
9
注意事项
|
Opera
完整支持
10.5
|
Safari
完整支持
3
|
WebView Android
完整支持
4.1
|
Chrome Android
完整支持
18
|
Firefox Android 完整支持 14 |
Opera Android
完整支持
11
|
Safari iOS
完整支持
1
|
Samsung Internet Android
完整支持
1.0
|
content-box
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 4 |
IE
完整支持
9
注意事项
|
Opera 完整支持 10.5 | Safari 完整支持 3 | WebView Android 完整支持 4.1 | Chrome Android 完整支持 18 | Firefox Android 完整支持 14 | Opera Android 完整支持 11 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
见实现注意事项。
要求使用供应商前缀或不同名称。
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