我试图找出一种方法使三个浮动 div 与三个浮动 div 中最大的浮动 div 的高度相匹配(通过 clearfix 解决方案,它是它们容器的高度)。
我的问题与这个问题完全一样,只有我的问题需要对答案的评论忽略:)(“如果两列有不同的背景颜色怎么办?”等)
所以真的不能假装。该页面使用类似于 iGoogle 使用 scriptaculous 的拖放机制,拖放可排序容器是浮动 div。如果我可以强制所有容器的高度相同,那么对用户来说事情会容易得多。
我越是寻找解决方案,越是看起来用纯 CSS 做不到。如果是这种情况,我需要使用一些 javascript,就这样吧。
提前致谢。
编辑: idrumgood 的链接是一个解决方案,但不是我最终使用的解决方案。我最终将他建议的 jQuery 函数移植到原型中,以避免冲突并避免为一个函数加载整个 jquery 库。
这是我最终使用的 javascript 函数端口:
function equalHeights(container) {
var children = $A(container.immediateDescendants());
var currentTallest = 0;
for (i = 0; i < children.length; i++) {
if (children[i].getHeight() > currentTallest) {
currentTallest = children[i].getHeight();
} //end if
} //end for
for (i = 0; i < children.length; i++) {
children[i].setStyle({ height: (currentTallest + 'px') });
} //end for
} //end equalHeights