English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive List of CSS Properties

CSS background-Position property usage and examples

CSS background-The position property sets the element'sbackground-imageThe initial position (i.e., the origin). Use the shorthandBackgroundProperties are usually more convenient.

The following table summarizes the usage context and version history of this property.

Default value:0%  0%
Applies to:All elements
Inheritance:None
Animatable:Yes.Please refer to Animation properties.
Version:CSS 1,2,3
JavaScript syntax:    object    object.style.backgroundPosition="center"

background-position的使用语法

Syntax of position usage

background-The syntax of this attribute is as follows: 1 position: [ percentage | length | left | center | right ] 2 or

values | initial | inherit-The following example demonstrates how to use background

Example
    background-p {/image: url("images
    background-smiley.png"); 5position:
0% center;
}/Test and see‹

Note:

If only one value is specified, the second value is assumed to be the center. If two values are used and at least one is not a keyword, the first value represents the horizontal position, and the second value represents the vertical position.

Attribute value

The following table describes the values of this attribute.Value
Descriptionbottom10Is equivalent to the horizontal position
Is equivalent to the vertical positioncenter5If not otherwise specified, it is equal to the horizontal position5Is equivalent to the horizontal position
0%, otherwise provide the vertical positionleft
Is equivalent to 0% of the horizontal position.right10Is equivalent to the horizontal position
0%.top
The vertical position is equal to 0%.length 10Actual pixel length. For example, using the value pair ' 2px10px, while the top left corner of the image is below the top left corner of the box20px.
percentagePercentage of the element size. For example, using the value pair '0% 0%', the top left corner of the image aligns with the top left corner of the element box.
initialSet this attribute to its default value.
inheritIf specified, the associated elements adopt the computed value of the background attribute of its parent element-position.

Browser compatibility

background-Browser compatibility of the position attribute, all major browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 3.5+

Further reading

Please refer to the following tutorials:CSS background,CSS3Background.

Related attributes:background,background-attachment,background-color,background-clip,background-image,background-origin,background-repeat,background-size.