正如标题所说,我需要两个div 一样高。它们应该尽可能高,以适应内容。当前的 CSS 是:
.portfolioleft{
float:left;
width:189px;
background-color: #436FAC;
min-height: 100px;
height: auto;
color: #FFF;
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
}
.portfolioleft img{
border-radius: 10px;
}
.portfolioright{
float:right;
width:500px;
background-color: #436FAC;
min-height: 100px;
height: auto;
color: #FFF;
padding: 20px;
margin-bottom: 20px;
border-radius: 10px;
}
.portfolioright a{
color:#FFFFFF;
}
div 的 html 是:
<div class="portfolioleft"><img src="img" alt="img" width="189" height="311" /></div>
<div class="portfolioright">
<h2>Title</h2>
<p>Text</p>
</div>
<div class="clear"> </div>
最佳答案
单靠 CSS 无法解决这个问题(除非您想要一个可以使用图像的 hack 解决方案)。您将需要实现 JS 解决方案。由于内容是动态的,并且您不知道列的高度,因此您需要访问 DOM 以确定最高列的高度,然后应用于指示的列。我经常使用以下内容,它运行良好且易于实现。
http://www.jainaewen.com/files/javascript/jquery/equal-height-columns.html
关于css - 两个动态高度相同的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10234683/