css3之导航transition图标的变化
原理:用了两个图片,一个有颜色,一个没有,都放在精灵图中。再用position定位,和transition变化。
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>导航transition图标变化</title>
<style>
*{
margin: 0;padding: 0;}
li ,ul {
list-style: none;
}
a{
text-decoration: none;}
nav{
width: 300px;
height: 50px;
margin: 100px auto;
/* border: springgreen solid 1px; */
}
nav ul li{
float: left;
}
nav li a{
display: block;
padding-left: 20px;
/* border: solid red 1px ; */
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
color: green;
font-weight: 600;
}
ul li:nth-child(1) a{
background: url(images/360bg.png) no-repeat 0px 21px ;
}
ul li:nth-child(1):hover a{
background: url(images/360bg.png) no-repeat 0px -13px ;
transition: 1s;
}
ul li:nth-child(2) a{
background: url(images/360bg.png) no-repeat 0px -48px ;
}
ul li:nth-child(2):hover a{
background: url(images/360bg.png) no-repeat 0px -87px ;
transition: 1s;
}
ul li:nth-child(3) a{
background: url(images/360bg.png) no-repeat 0px -125px ;
}
ul li:nth-child(3):hover a{
background: url(images/360bg.png) no-repeat 0px -166px ;
transition: 1s;
}
ul li:nth-child(4) a{
background: url(images/360bg.png) no-repeat 0px -207px ;
}
ul li:nth-child(4):hover a{
background: url(images/360bg.png) no-repeat 0px -248px ;
transition: 1s;
}
</style>
</head>
<body>
<nav>
<ul>
<Li><a href="">热点</a></Li>
<Li><a href="">首页</a></Li>
<Li><a href="">新闻</a></Li>
<Li><a href="">视频</a></Li>
</ul>
</nav>
</body>
</html>