DIV CSS BackGround属性研究

在设置background-image属性时,有很多属性

1、background:url("图片路径") [no-repeat];

background:url("../images/images/up.jpg") no-repeat; 表示不重复显示图片

2、background-position

版本:CSS1 兼容性:IE6 7+ FF+ 继承性:无
语法
background-position :length || length
background-position :position || position
取值: position : top | center | bottom | left | center | right


说明
设置或检索对象的背景图像位置。必须先指定 background-image 属性。
该属性定位不受对象的补丁属性( padding )设置影响。
默认值为: 0% 0% 。此时背景图片将被定位于对象不包括补丁( padding )的内容区域的左上角。
如果只指定了一个值,该值将用于横坐标。纵坐标将默认为 50% 。如果指定了两个值,第二个值将用于纵坐标。
如果设置值为 right center ,因为 right 作为横坐标值将会覆盖 center 值,所以背景图片将被居右定位。
对应的脚本特性为 backgroundPosition 。

示例
div { background: url(\"images/aardvark.gif\"); background-position: 35% 80%; }
menu { background: url(\"images/aardvark.gif\"); background-position: 35% 2.5cm; }
a { background: url(\"images/aardvark.gif\"); background-position: 3.25in; }
body { background: url(\"images/aardvark.gif\"); background-position: top 0px right 0px; }
其实background-position就是用来控制background-image的position
如果指定一个值,该值用于横坐标,纵坐标采用默认,即50%(center)
如果指定两个值,第二个值用于纵坐标,
例如你写定:background-position: left center;其实和background-position: left;是一样的都是左对齐,垂直居中对齐
如果指定:background-position: left left;就是左对齐,垂直居中对齐
如果指定:background-position: right right;就是右对齐,垂直居中对齐
如果指定:background-position: left right;其实这两个值都是在横坐标上的作用,right会覆盖left属性,所以最后显示的还是就是右对齐,垂直居中对齐。
除了left center right 还有TOP bottom,这两个分别是顶部对齐,底部对齐.
例如指定:background-position: left top;那么图片将位于左上角。
利用这个特性可以实现一个非常酷的效果
根据以上实例还可以如下写法,兼容性也比较好
.test {background: url(title_bg2.jpg) no-repeat -203px 0px; 200px; height:36px;}
.title {background: url(title_bg.jpg) no-repeat left 0px; 83px; height:36px;}

3、background-attachment

取值: fixed | scroll | inherit

fixed  就是背景图片固定  不会随着页面滚动而变化,IE、Firefox 效果不同 Firefox有效果,IE6不起效果*/

4、background-repeat

版本:CSS1  兼容性:IE4+ NS4+ 继承性:无

语法:
background-repeat : repeat | no-repeat | repeat-x | repeat-y
参数:
repeat :  背景图像在纵向和横向上平铺
no-repeat :  背景图像不平铺
repeat-x :  背景图像在横向上平铺
repeat-y :  背景图像在纵向平铺
说明:
设置或检索对象的背景图像是否及如何铺排。必须先指定对象的背景图像。
对应的脚本特性为backgroundRepeat。请参阅我编写的其他书目。
示例:
menu { background: url("images/aardvark.gif"); background-repeat: repeat-y; }
p { background: url("images/aardvark.gif"); background-repeat: no-repeat; }

原文地址:https://www.cnblogs.com/hakuci/p/1913043.html