如何将浮动框元素(高度不同)组织成行(使用JavaScript)

如何将浮动框元素(高度不同)组织成行(使用JavaScript),javascript,css,css-float,yui,Javascript,Css,Css Float,Yui,我有一个块元素列表。每个块元素都有一定的高度(不同)。我想将块元素组织成行 第一次尝试是迭代所有元素,并将它们的高度设置为heighest元素之一。但是,这会导致行之间出现间隙,因为总有一个元素的高度明显高于其他元素 所以,我想做同样的事情,但是检测行并相应地设置高度。但是,当element.getComputedStyle('left')在浮动元素上返回undefined时,我就遇到了这样的问题 我可以使用的其他功能(使用YUI,但这不重要)?或者完全使用另一种方法?您可以使用此纯CSS解决方

我有一个块元素列表。每个块元素都有一定的高度(不同)。我想将块元素组织成行

第一次尝试是迭代所有元素,并将它们的高度设置为heighest元素之一。但是,这会导致行之间出现间隙,因为总有一个元素的高度明显高于其他元素

所以,我想做同样的事情,但是检测行并相应地设置高度。但是,当
element.getComputedStyle('left')
在浮动元素上返回
undefined
时,我就遇到了这样的问题


我可以使用的其他功能(使用YUI,但这不重要)?或者完全使用另一种方法?

您可以使用此纯CSS解决方案:

HTML:

链接到JSFIDLE:

您可以使用此纯CSS解决方案:

HTML:

链接到JSFIDLE:

不要创建固定高度的元素行以消除间隙。。。你能考虑使用吗?David Desandro做了一个不需要jQuery的框架不可知的版本。我正在(慢慢地)为YUI3开发一个端口。完成后,我将在YUI Gallery中发布它,而不是创建固定高度元素的行,以消除间隙。。。你能考虑使用吗?David Desandro做了一个不需要jQuery的框架不可知的版本。我正在(慢慢地)为YUI3开发一个端口。当我完成后,我会在YUI图库中发布它
<div class="row">
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
</div>    

<div class="row">
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
    <div>I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.I can't. As much as I care about you, my first duty is to the ship. The unexpected is our normal routine.</div>
</div>
.row div {
    display:table-cell;
    width:25%;
}