CSS样式-精灵图(雪碧图)
只请求一次图片加载,然后通过控制图片的background-position来获得想要的样式效果。
<!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 type="text/css">
#nav {
text-align: center;
}
#nav>a {
display: inline-block;
width: 120px;
height: 50px;
background-image: url(image/bgall.png);
line-height: 50px;
color: #fff;
text-decoration: none;
background-position: left top;
}
#nav>a:hover {
background-position: left -50px;
}
</style>
</head>
<body>
<div id="nav">
<a href="#">测试菜单</a>
<a href="#">测试菜单</a>
<a href="#">测试菜单</a>
<a href="#">测试菜单</a>
<a href="#">测试菜单</a>
<a href="#">测试菜单</a>
</div>
</body>
</html>