在下面的代码中,我想保持.link1
和.link2
隐藏,并且在将鼠标悬停在 上时.image
,我希望通过过渡效果使它们可见,以便link1
从左侧link2
移动和从右侧移动,它们都到达 div 的中心.
我正在尝试以下代码,但它不起作用:
HTML:
<div class="wrap">
<div class="image"><img src="http://farm9.staticflickr.com/8043/8357588952_94cee71fef.jpg" /></div>
<div class="hover">
<a class="link1">Link 1</a>
<a class="link2">Link 2</a>
</div>
</div>
CSS:
.wrap{
margin: 100px;
width: 500px;
overflow: hidden;
position: relative;
}
.image{
border: 1px solid red;
-webkit-transition: all 0.4s;
-moz-transition: all 0.4s;
transition: all 0.4s;
}
.hover{
position: absolute;
top: 40%;
}
.link1{
display: inline-block;
width: 70px;
height: 30px;
background: yellow;
position: absolute;
left: -100%;
}
.image:hover .link1{
left: 40%;
}
.link2{
display: inline-block;
width: 70px;
height: 30px;
background: yellow;
position: absolute;
right: -100%;
}
.image:hover .link2{
right: 40%;
}
演示:http: //jsfiddle.net/XjTyJ/