[英]How to make div to match image height with CSS
Following js fiddle http://jsfiddle.net/9pn8Z/5/ contains element I'm currently working on. 以下js小提琴http://jsfiddle.net/9pn8Z/5/包含我目前正在处理的元素。 This is part of page layout, it will be duplicated with diffrent images.
这是页面布局的一部分,它将与不同的图像重复。 While width of image is fixed, height varies and i got problem with that.
虽然图像的宽度是固定的,但高度变化,我遇到了问题。 Element will come in one of few widths, height would vary depending on size of source image.
元素将具有几个宽度中的一个,高度将根据源图像的大小而变化。
My goal is to make height of rt_tileoverlay div, that slides on when image is hovered same as height of image. 我的目标是使rt_tileoverlay div的高度在图像悬停时与图像高度相同时滑动。 I would like to avoid javascript and just stick to css
我想避免使用javascript而只是坚持使用css
Here is My code: 这是我的代码:
<div class="rt_tilewrap">
<a href="www.google.com">
<div class="rt_imgwrap">
<div class="rt_tileoverlay"></div>
<img class="rt_timg" src="http://i.imgur.com/cepjcsGb.jpg" />
</div>
</a>
<div class="rt_tiletext">
<p>wards are focused oni wards are focused oni
wards ards are focused oni wards areds are focused oni
wards are focused oni wards are focused oni wards are
focused oni wards are focu wards are focused i .</p>
</div>
</div>
.rt_tilewrap {
padding: 10px;
display: inline-block;
text-align: left;
vertical-align: top;
background: rgba( 22, 255, 22, 0.3);
width:355px;
}
.rt_tiletext {
padding: 5px 0 5px 0;
color: #666666;
float:left;
line-height: 1.1em;
text-align: justify;
display: block;
background:skyblue;
}
.rt_tiletext p{
padding: 0;
margin: 0;
}
.rt_timg {
width: 100%;
height: auto;
display:block;
position: relative;
float:left;
}
.rt_imgwrap{
overflow:hidden;
}
.rt_tileoverlay {
height: 100%;
width: 0;
color:white;
overflow:hidden;
position: absolute;
background-color: rgba(255, 255,0, 0.5);
transition: all 0.4s ease-in-out;
position: margin-top: 0px;
margin-left: 0px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-ms-transition: all .4s ease;
-o-transition: all .4s ease;
transition: all .4s ease;
z-index: 100;
}
.rt_imgwrap:hover > .rt_tileoverlay {
width:355px;
}
Thanks in adavnce for your suggestions for how to solve it. 非常感谢你提出如何解决它的建议。
You need to set the relative parent of the rt_tileoverlay
to take the full height: 您需要将
rt_tileoverlay
的相对父级设置为采用完整高度:
.rt_imgwrap{
position:relative;
overflow:hidden;
}
The demo http://jsfiddle.net/9pn8Z/6/ 演示http://jsfiddle.net/9pn8Z/6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.