案例一 利用循环实现精灵图布局
-
分析:首先精灵图图片排列是由规律的
-
核心思路:
- 利用for循环,修改精灵图的背景位置 background-position
- 然后用软件测量,得到规律:让for循环里面的i的索引号*44就是每个图片的y坐标
<style>
* {
padding: 0px;
margin: 0px;
}
li {
list-style-type: none;
}
.box {
width: 250px;
margin: 100px auto;
}
.box li {
float: left;
width: 24px;
height: 24px;
background-color: pink;
margin: 15px;
background: url(images/taobao.png) no-repeat;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li></li>