共计 977 个字符,预计需要花费 3 分钟才能阅读完成。
css background-position 定义与用法
background-position 属性设置背景图像的起始位置。
注意 对于这个工作在 Firefox 和 Opera,background-attachment 必须设置为 "fixed(固定)".
默认值: | 0% 0% |
---|---|
继承: | no |
版本: | CSS1 |
JavaScript 语法: | object object.style.backgroundPosition="center" |
css background-position 属性值
值 | 描述 |
---|---|
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 属性设置应该从父元素继承 |
css background-position 浏览器支持
所有主要浏览器都支持 background-position 属性。
注意 IE7 和更早的版本不支持 "inherit(继承)" 的值。IE8 需要定义!DOCTYPE。IE9 支持 "inherit(继承)"。
css background-position 实例
如何定位 background-image:
body{background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
更多实例
如何设置页面背景图像
这个例子演示了如何在页面上设置 background-image。
如何使用%来定位背景图像
这个例子演示了如何使用%设置页面上的图像位置。
如何使用像素来定位背景图像
这个例子演示了如何使用像素设置页面上的图像位置。
正文完