CSS-Sprite 雪碧图
所谓雪碧图其实就是把一些小图片或者图标集中放在一张图片上,真实项目中主要功能就是可以减少http请求
准备工作:
代码:简单实现原理
<!DOCTYPE html>
<html>
<head>
<title>sprite</title>
<style type="text/css">
.parent{
width: 25px;
height: 20px;
border: solid 2px red;
background: url(./sprite.png);
background-repeat: no-repeat;
}
.parent:hover{
background-position: 0 -50px;
}
.copy{
margin-top: 100px;
width: 100px;
height: 100px;
background: url(./2016.png);
}
</style>
</head>
<body>
<div class="parent">
</div>
<div class="copy"></div>
</body>
</html>
实现效果:
parent区域正常展示第一个图标,当鼠标hover时,利用background-position属性,来移动背景图片位置,实现图标切换