语法:
background-color : transparent | color
取值:
transparent |
: |
默认值。背景色透明 |
color |
: |
指定颜色。请参阅 颜色单位 和 附录:颜色表 |
说明:
设置或检索对象的背景颜色。
当背景颜色与背景图像( background-image )都被设定了时,背景图片将覆盖于背景颜色之上。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundColor 。
语法:
background-image : none | url ( url )
取值:
none |
: |
默认值。无背景图 |
url ( url ) |
: |
使用绝对或相对 url 地址指定背景图像 |
说明:
设置或检索对象的背景图像。
当背景图像与背景颜色( background-color )都被设定了时,背景图片将覆盖于背景颜色之上。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundImage
url为相对路径设置时容易出错要注意!!
语法:
background-repeat : repeat | no-repeat | repeat-x | repeat-y
取值:
repeat |
: |
默认值。背景图像在纵向和横向上平铺 |
no-repeat |
: |
背景图像不平铺 |
repeat-x |
: |
背景图像仅在横向上平铺 |
repeat-y |
: |
背景图像仅在纵向上平铺 |
说明:
设置或检索对象的背景图像是否及如何铺排。必须先指定对象的背景图像(
background-image)。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundRepeat 。
语法:
background-position :
length || length
background-position :
position || position
取值:
length |
: |
百分数 | 由浮点数字和单位标识符组成的长度值。请参阅 长度单位 |
position |
: |
top | center | bottom | left | center | right |
说明:
设置或检索对象的背景图像位置。必须先指定
background-image 属性。
该属性定位不受对象的补丁属性( padding )设置影响。
默认值为: 0% 0% 。此时背景图片将被定位于对象不包括补丁(
padding)的内容区域的左上角。
如果只指定了一个值,该值将用于横坐标。纵坐标将默认为 50% 。如果指定了两个值,第二个值将用于纵坐标。
如果设置值为 right center ,因为 right 作为横坐标值将会覆盖 center值,所以背景图片将被居右定位。
对应的脚本特性为 backgroundPosition 。
.html代码如下:
.css代码如下:
显示如下: