CSS使用图片做背景,如何精确定位图片位置

2024年11月12日 13:18
有1个网友回答
网友(1):

根据你的图片做了下面的样式,主要做法是定位,切割图片,可以使用windows的画图工具先定位每个你需要的图片的位置(在下面的状态栏有坐标,得到的坐标前面加上一个负号),图片左上角为x/y对应的0/0, background-image:相对地址指定背景图像, background-position:指定背景图像位置, 下面是例子,这个要多练习研究就会了。多看看CSS方面的说明 .icon {background-image: url(back_image.png)} .head {height: 26px; background-position: -42px -222px; background-repeat: no-repeat;} .btn {cursor:pointer; border:0; width: 107px; height: 26px; background-image: url(back_image.png); background-position: -42px -222px; background-repeat: no-repeat;}