css 图片偏移问题

html-css013

css 图片偏移问题,第1张

把每一小格 都引入背景 例如:

background-image: url(bgimage.gif)

再分别对格子做背景图片定位 例如:

background-position:0px 0px /* 这里的位置和图片相对应 */

首先你要知道要截取的图片在整张图片中的偏移量以及大小。然后:

<div style="width:wwwpxheight:hhhpxbackground:url(图片url) no-repeat -lllpx -tttpx"></div>

其中www是要截取的小图片的宽度,hhh则是高度;

lll是小图片的左边在大图片的偏移量,ttt则是上边的偏移量。

请注意负号不能省略!

background:url(images/loginbackground.png)top no-repeat 0px 10px

等同与

background:url(images/loginbackground.png)top no-repeat

background-position: 0px 10px//水平方向(以左上角为原点,x方向)移动 0像素,垂直方向(y轴方向)即向下以动 10 像素

***注意:0px 不能省略,否则默认为x方向移动的距离。也可以设置为百分比值。

修改后: