如何将浮动框元素(具有不同的高度)组织成行(使用JavaScript)
How to organize floating box elements (with varying height) into rows (with JavaScript)
我有一个块元素列表。每个块元素都有一定的高度(不同的高度)。我想把块元素组织成行。
第一次尝试是遍历所有元素并将其高度设置为最高元素之一。但是,这会导致行与行之间出现空白,因为总是有一个元素明显高于其他元素。
所以,我想做同样的,但检测行并设置相应的高度。但是,我这样做有问题,因为element.getComputedStyle('left')
返回浮动元素的undefined
。
我可以使用的其他函数(使用YUI,但这应该无关紧要)?或者完全使用另一种方法?
您可以使用以下纯CSS解决方案:
HTML:<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>
CSS .row div {
display:table-cell;
width:25%;
}
链接到jsFiddle:http://jsfiddle.net/innerurge1/Ys5Kw/
相关文章:
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 使用javascript设置iframe的高度
- javascript skrollr基于动态内容更新窗口高度
- 当我使用高度百分比时,谷歌地图javascript api不会显示
- 如何确定相对较新版本的IE的高度和宽度(IE8不喜欢从JavaScript设置这种样式吗?
- jquery插件或javascript方法自动调整文本输入(而非文本区域)(固定宽度)可变高度的大小
- 使用asp.net FileUpload时从javascript获取图像宽度和高度
- whay可以't我使用javascript同时更改图像的高度和宽度
- 如何在HTML CSS JavaScript中根据纵横比调整高度或宽度
- 尝试使用window.innerHeight和Javascript设置图像高度
- 使用JavaScript更改带有窗口高度的元素样式
- 使用Javascript匹配两个HTML元素的高度
- 使用纯Javascript设置最小高度属性
- Javascript图像宽度和高度未定义值
- 如何在有或没有javaScript的android中获取每个页面的内容高度
- Javascript如何设置我自己的img宽度和高度(调整大小)
- 获取计算高度-Javascript-而不是jQuery
- 获取图像宽度-高度javascript
- 随机高度Javascript