Style backgroundPosition property
The Style object
Definition and Usage
The backgroundPosition property sets or returns the position of the background image of an element.
Syntax
Set the backgroundPosition property:
Object.style.backgroundPosition="
position
"
Return the backgroundPosition property:
Object.style.backgroundPosition
**Tip:** The default value of the backgroundPosition property is: 0% 0%.
| Value | Description |
|---|---|
| top left |
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right | 如果仅指定一个关键字,其他值将是 "center"。 |
| x% y% | The x value indicates the horizontal position and the y value indicates the vertical position. The top-left corner is 0% 0%. The bottom-right corner is 100% 100%. If only one value is specified, the other will be 50%. | | xpos ypos | The x value indicates the horizontal position and the y value indicates the vertical position. The top-left corner is 0 0. The unit can be pixels (0px 0px) or any other CSS unit. If only one value is specified, the other will be 50%. You can mix % and units. | | inherit | The background-position property is inherited from the parent element. |
Browser support





All major browsers support the backgroundPosition property.
**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Change the position of the background image:
Try it »
The Style object