水平对齐2个不同高度的div,并保持在各自的列内

时间:2012-10-31 17:45:42

标签: css

我需要将2个div放在一起,以便它们水平对齐。如果右边的div更高,它不应该在下面,而应该在它下面包裹。

<html>

<style>
#left, #right {float:left; border:1px solid black; margin:10px;}
</style>

<div id="container">

<div id="left">
this is an image, the hight and width can vary
</div>
<div id="right">
this div should never wrap underneath the image.  if it is higher than left image it needs to wrap under itself so the space directly beneath the image is respected
</div>

</div>
<div style='clear:both;'></div>

<hr>

<div id="left">
this is an image, the hight and width can vary
</div>
<div id="right">
this div should never wrap underneath the image.  if it is higher than left image it needs to wrap under itself so the space directly beneath the image is respected
</div>

</div>
<div style='clear:both;'></div>
</html> 

1 个答案:

答案 0 :(得分:2)

#left, #right {float:left; border:1px solid black; margin:10px; width:45%;}