/*背景重复、水平重复、垂直重复、不重复;背景尺寸大小;背景定位;background-repeat;背景固定;背景属性简写*/ body{background-image: url(xxx.jpg);background-repeat:repeat ;}/*背景重复,默认是重复的*/ body{background-image: url(xxx.jpg);background-repeat:repeat-x;}/*水平重复*/ body{background-image: url(xxx.jpg);background-repeat:repeat-y;}/*垂直重复*/ body{background-image: url(xxx.jpg);background-repeat:no-repeat ;}/*背景不重复*/ /*图片大小:background-size*/ div{background-image: url(xxx.jpg);background-repeat:no-repeat;background-size:80% 50%;}/*按百分比或像素设置大小*/ div{background-image: url(xxx.jpg);background-repeat:no-repeat;background-size:contain;}/*图片扩展至最大尺寸,使宽高适应内容区域,不是拉伸,保持原来宽高比*/ div{background-image: url(xxx.jpg);background-repeat:no-repeat;background-size:cover;}/*图片完全覆盖内容区域,背景某些部分可能无法显示*/ /*图片定位: background-position background-position:center; 居中 background-position:right bottom; 右下角 background-position:right top; 右上角 background-position:left bottom; 左下角 background-position:left center; 左侧垂直居中 background-position:right center; 右侧垂直居中 background-position:center bottom; 底部居中 background-position:right center; 顶部居中 background-position:100px; 垂直居中,并向右偏移 */ div{background-image: url(xxx.jpg);background-repeat:no-repeat; background-position:10px 50px;}/*左侧偏移和上侧偏移*/ div{background-image: url(xxx.jpg);background-repeat:no-repeat; background-position:left bottom;}/*右下角对齐*/ /*背景固定:background-attachment:fixed*/ div{background-image: url(xxx.jpg);background-repeat:no-repeat; background-attachment:fixed;}/*滚动界面后,图片永远在固定位置*/ /*背景属性简写background*/ div{background:#00ff00 url(xxx.jpg) no-repeat 20px 100px/300px 90px fixed ;}/*颜色 图片地址 不重复背景 位置/大小 固定位置*/ /*图片不要用一个个小图片,因为一个图片就要从服务器发一次请求,建议用一个大图片后用位置范围来锁定需要的内容*/