要学会用fireworkes软件,精确测量给的图片里每个图案的大小和位置。
例子拼 pink 这个单词,在盒子里放这个图片的特定图案字母P。那么需要设置好盒子,并设定好到底要显示这个精灵图的哪个部位(靠坐标定位)。以此类推设置每一个字母的盒子。
最终显示效果如图:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>精灵图拼单词</title>
<style>
span {
display: inline-block;
}
.p {
width: 100px;
height: 112px;
background: url(../images/abcd.jpg) no-repeat -493px -276px;
}
.i {
width: 60px;
height: 108px;
background: url(../images/abcd.jpg) no-repeat -327px -142px;
}
.n {
width: 108px;
height: 109px;
background: url(../images/abcd.jpg) no-repeat -215px -141px;
}
.k {
width: 105px;
height: 114px;
background: url(../images/abcd.jpg) no-repeat -495px -142px;
}
</style>
</head>
<body>
<span class="p">p</span>
<span class="i">i</span>
<span class="n">n</span>
<span class="k">k</span>
</body>
</html>