在以下 HTML 中, 的初始位置.layer
设置为top: -100%
,我想在将鼠标悬停在.image
div 上时更改它。我正在尝试以下代码,但它似乎在悬停时没有做任何事情。
HTML:
<div class="box">
<div class="image">
<a href="#"><img src="http://farm9.staticflickr.com/8356/8332233161_18e3a75de0_m.jpg" ></a>
</div>
<div class="layer">Hide it first, show on hover over image</div>
<div class="other">other</div>
</div>
CSS:
.box{
border: 1px solid red;
width: 240px;
}
.box .image{
position: relative;
overflow: hidden;
}
.box .layer{
width: 240px;
height: 146px;
background: green;
position: absolute;
top: -100%;
}
.box .image:hover .layer{
top: 0
}
JSFiddle:http: //jsfiddle.net/pY9jx/