CSS background-position property
Examples
How to locate the background-image:
{
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
try it"
Tag definitions and instructions
background-position property sets the starting position of the background image.
Note that for this to work in Firefox and Opera, background-attachment must be set to "fixed (fixed)."
Defaults: | 0% 0% |
---|---|
inherit: | no |
version: | CSS1 |
JavaScript syntax: | object object.style.backgroundPosition = "center" |
Browser Support
Figures in the table represent the first browser to support the version number of the property.
Attributes | |||||
---|---|---|---|---|---|
background-position | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
NOTE: IE8 browser and earlier versions do not support element has a plurality of background images.
Property Value
值 | 描述 |
---|---|
left top left center left bottom right top right center right bottom center top center center center bottom |
如果仅指定一个关键字,其他值将会是"center" |
x% y% | 第一个值是水平位置,第二个值是垂直。左上角是0%0%。右下角是100%100%。如果仅指定了一个值,其他值将是50%。 。默认值为:0%0% |
xpos ypos | 第一个值是水平位置,第二个值是垂直。左上角是0。单位可以是像素(0px0px)或任何其他 CSS单位 。如果仅指定了一个值,其他值将是50%。你可以混合使用%和positions |
inherit | 指定background-position属性设置应该从父元素继承 |
Online examples
How to set page background image
This example demonstrates how to set the background-image on the page.
How to position a background image using%
This example demonstrates how to use the position of the image on the% settings page.
How to position a background image using pixels
This example demonstrates how to use the image on a pixel location settings page.
related articles
CSS tutorial: CSS Background
CSS Reference Manual: background-Image property