Position the background image relative to the content box:
document.getElementById("myDIV").style.backgroundOrigin = "content-box";
Try it Yourself »
The backgroundOrigin property sets or returns what the background-position property is relative to.
Note: If the background-attachment property for the background image is "fixed", this property has no effect.
HTML Styles: The background Property
CSS Tutorial: CSS Backgrounds
CSS3 Tutorial: CSS3 Backgrounds
CSS Reference: The background-origin property
Return the backgroundOrigin property:
object.style.backgroundOrigin
Set the backgroundOrigin property:
object.style.backgroundOrigin = "padding-box|border-box|content-box|initial|inherit"
Value | Description |
---|---|
padding-box | Default value. The background image is positioned relative to the padding box |
border-box | The background image is positioned relative to the border box |
content-box | The background image is positioned relative to the content box |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | padding-box |
---|---|
Return Value: | A String, representing the background-origin property of an element |
CSS Version | CSS3 |
backgroundOrigin
is a CSS3 (1999) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!