background-position属性设置背景图像的起始位置。
注意对于这个工作在Firefox和Opera,background-attachment必须设置为 "fixed(固定)"。
| 默认值: | 0% 0% | 
|---|---|
| 继承: | no | 
| 版本: | CSS1 | 
| JavaScript 语法: | object object.style.backgroundPosition="center" | 
background-position: horizontal vertical
水平是
percentage | length | left | center | right
垂直是
percentage | length | top | center | bottom
| 值 | 描述 | 
|---|---|
| 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属性设置应该从父元素继承 | 
如何定位background-image:
body
{
background-image:url('smiley.gif');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
}
如何设置页面背景图像
这个例子演示了如何在页面上设置background-image。
如何使用%来定位背景图像
这个例子演示了如何使用%设置页面上的图像位置。
如何使用像素来定位背景图像
这个例子演示了如何使用像素设置页面上的图像位置。
表格中的数字表示支持该属性的第一个浏览器版本号。
| 属性 | |||||
|---|---|---|---|---|---|
| background-position | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 | 
注意: IE8 及更早的浏览器版本不支持一个元素有多个背景图片。
CSS 教程: CSS Background
CSS 参考手册: background-image 属性
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2025 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。