在下面的HTML中,.layer
的初始位置设置为top: -100%
,我想将其悬停在.image
div上时将其更改。我正在尝试下面的代码,但它似乎没有做任何悬停。CSS:更改悬停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/
谢谢你的详细解答。我刚刚在您的示例中添加了保证金,但无法正常工作。即使.image位置是相对的,.layer似乎并不关心:http://jsfiddle.net/pY9jx/12/ – user1355300