我有以下html标记
<div class="wrapper" style="position: relative;" >
<img src="..." style="width:100%; height:auto">
<div class="description" style="position:absolute;left:0;bottom:0;width:100%">
figure caption
</div>
</div>然后我点击图片,将标题移到图片的底部。css标记看起来像这样
.wrapper.full .description{
transform: translate(0,100%);
}
.description{ transition: all .4s ease-in-out;}但问题是包装器的高度并没有像我想要的那样改变。我希望高度为h = image_heigth + caption_height,因为下面有更多的内容,我想把它往下推,并为描述分配空间。实际上,描述出现在包装器之外,因为它不会改变大小,并且与下面的内容重叠。有什么帮助吗?JS代码
$('.wrapper img').click(function(){
var wrapper= $(this).parents('.wrapper');
wrapper.addClass('full');
)};发布于 2015-08-30 00:54:31
您可以尝试下面的代码: HTML
<div class="wrapper" style="position: relative;" >
<img src="http://lorempixel.com/200/200/" style="width:100%; height:auto">
<div class="caption" style="position:absolute;left:0;bottom:0;width:100%">
figure caption
</div>
</div>
<!--Design 2-->
<div class="wrapper sample_2" style="position: relative;" >
<img src="http://lorempixel.com/200/200/" style="width:100%; height:auto">
<div class="caption" style="position:absolute;left:0;bottom:0;width:100%">
figure caption
</div>
</div>Css
.wrapper{
width:200px;
height:200px;
padding:10px;
background:red;
overflow:hidden;
transition:all .5s;
}
.wrapper:hover{
height:400px;
}
.wrapper .caption{
width:100%;
height:200px;
top:220px;
left:0;
right:0;
bottom:0;
position:absolute;
background:green;
padding:10px;
box-sizing:border-box;
}
/*Design 2*/
.wrapper.sample_2:hover{
height:200px;
}
.wrapper.sample_2 .caption{
transition:all .5s;
}
.wrapper.sample_2:hover .caption{
top:0;
}在jsfiddle上观看此现场演示
查看jsfiddle-2上的第二个演示
https://stackoverflow.com/questions/32288378
复制相似问题