刚刚带大家学习了一下二级菜单的写法,这次我们来聊聊精灵图的使用,因为我想大家在仿写其他页面的时候总会遇到各种各样的小图标,很多小图标都能找到,这里推荐大家去搜 -阿里矢量图-这是阿里的矢量图库,里面的矢量图基本能满足大部分人的需求,但是一些奇奇怪怪的小图标确实是找不到,这个时候推荐大家使用精灵图,精灵图的对于很多大项目来说是很友好的,为什么呢,因为精灵图只需要访问一次,不需要占用服务器端太多的内存。
因为精灵图一般位于导航栏里面,所以我们还是要先见一个框出来,也是差不多1200px,
浏览器效果如下
然后加入html和css 也就是简单的图片,注意两张用的是同一张图
主要的就是利用背景图片的x y 轴来完成图片移动到正确的位置上
全部代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.wrapper{
width: 100%;
height: 80px;
background-color: cyan;
}
.h-wrapper{
width: 1200px;
height: 80px;
background-color: white;
margin: 0 auto;
}
.f1 div{
float: left;
}
.tu-one{
width: 130px;
height: 40px;
background-image: url('img/topfoot-spr.png');
background-repeat: no-repeat;
background-position: -213px 3px;
}
.tu-two{
margin-left: 50px;
width: 165px;
height: 40px;
background-image: url('img/topfoot-spr.png');
background-repeat: no-repeat;
background-position: -214px -38px;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="h-wrapper f1">
<div class="tu-one"></div>
<div class="tu-two"></div>
</div>
</div>
</body>
</html>