我有3张图片,每张图片后都有一个div。我试图调整所有图像的高度,使之与div后面的高度相同。多张图片只能得到第一格的高度
但是,所有的图像都被赋予了高度的第一个格,而不是后面的那个。
我相信这是因为当使用$(".text").outerHeight()
时,它始终获得第一个<div class="text">
的高度。我已经使用这个.each
功能来解决这个尝试,但都无济于事:
$('.container').each(function(i, obj) {
$(".container").find('img').css("height", $(".text").outerHeight());
});
这是我没有.each
功能全码:
$(".container").find('img').css("height", $(".text").outerHeight());
div.container {
border: 1px solid;
margin-bottom: 30px;
}
img {
float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<img src="https://images-na.ssl-images-amazon.com/images/M/[email protected]@._V1_SX300.jpg" alt="RED" />
<div class="text">
<h2>Red</h2>
<p>When his peaceful life is threatened by a high-tech assassin, .</p>
</div>
</div>
<div class="container">
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTAyNzQyNTcwNjVeQTJeQWpwZ1[email protected]_V1_SX300.jpg" alt="White House Down" />
<div class="text">
<h2>White House Down (2013)</h2>
<p>While on a tour of the White House with his young daughter, a Capitol policeman springs into action to save his child and protect the president from a heavily armed group of paramilitary invaders.</p>
</div>
</div>
<div class="container">
<img src="https://images-na.ssl-images-amazon.com/images/M/[email protected]_V1_SX300.jpg" alt="White House Down" />
<div class="text">
<h2>White House Down (2013)</h2>
<p>While on a tour of the White House with his young daughter, a Capitol policeman springs into action to save his child and protect the president from a heavily armed group of paramilitary invaders.</p>
</div>
</div>
非常感谢,这本来是方便的,如果我早知道关于'.prev'功能 - 我从来没有想过做这种方式的。再次感谢! –
@ TheCodesee np。你也可以在相反的方向使用'$ .next()' –