|
首先是导入背景图片,background-image属性,它后面一般会接一个url(。。),里面存有图片的路径,以斜杠/开头的表示绝对路径,否则表示相对路径,这里的相对路径是指相对于css样式文件的路径而不是页面文件的存储位置。当然也可以以网络地址来引用图片,这样的路径必须以协议开头,如:http://。
background-repeat,该属性有四种取值,repeat,no-repeat,repeat-x,repeat-y,默认的为repeat。
background-position,有三种取值方式:一个是采用center, top,right,left,bottom这几种来对图片定位,还有一种更为精确的采用像素来定位,如background-position:8px 10px;三是采用百分比格式,如:background-position:10% 50%;默认值是左上方。这里的定位是相对于背景图片所在的容器而言的。background-position会影响background-repeat的效果,因为图片重复是在图片定位完成之后进行的。
background-attachment,这个属性有两个值fixed,scroll,默认是scroll,它表示背景不随页面scroll而滑动。需要注意的是ie6和它之前的ie版本,这个属性只能针对<body>标签。
背景图片的简写,background: background-color background-image background-attachment background-position background-repeat, 如:body { background: #FFF url(bullseye.gif) scroll center center no-repeat; }
|
|