我有一个使用外面两列,并在设计中的标题部分外柱和下面两列,像这样的一个:使柱的高度相等 - 筑巢
**************************
* header *
**************************
| | |
| | |
| out1 | out2 |
| | |
| | |
| | |
**************************
* footer *
**************************
**************************
* header *
**************************
| title | |
|________________| |
| | | |
| | | |
| in1 | in2 | |
| | | |
| | | |
| | | |
**************************
* footer *
**************************
现在,一些的列有边框,所以out2有左边框,in1有右边框。整个页面有一个微弱的大背景平铺图像。
我想使列使用jQuery相同的高度,所以列边框看起来是平等的。
我这样做的方式是让外部列的高度相同,然后尝试使内部列的高度相同,并且尝试使它们一直伸展到底部他们的in1容器(在out2比out1高的情况下)
难以置信的是out1中的标题部分需要在计算中考虑。
OUT1 OUT2 &包含与layout
类,便于选择查询和IN1一个div内,IN2 &标题被包裹一个div内部与类layout
和nested
(嵌套和外之间容易选择和分化)。
每个布局容器也有一个div.clear来取消浮动列高度的效果。
这是我在准备处理程序运行代码:
var layouts = $('.layout').get();
// sort to have .nested last
layouts.sort(function(a,b){
return $(a).hasClass('nested');
});
$(layouts).each(function(){
var $this = $(this);
var container_height = $this.height();
if ($this.hasClass('nested'))
{
var parent = $this.parent();
var heading = $this.siblings('h1');
var parent_h = parent.innerHeight();
container_height = parent_h-heading.innerHeight() - 9; // (i'm not sure why I need -9 here, just go with it, it's not critical to the problem)
}
var columns = $this.find('> div').not('.clear');
columns.each(function(){
var padding = $(this).innerHeight() - $(this).height();
$(this).height(container_height - padding);
});
});
它主要从事。在safari(mac * ipad)上,我发现它有助于在运行该代码之前设置一个延迟(即使它在一个准备好的事件中被触发),但是存在随机的不一致性,其中列高度误计算得太小,并导致布局流动在页脚之上。
我曾考虑过使用Faux Columns,但由于内部标题部分的原因,文档上的边框和背景图片的组合使得它变得不可能(人造列背景不应显示在该区域内,但我仍应该看穿页面背景)
你有没有什么聪明的想法可以使这个更简单,或者你能提供一些见解,为什么偶尔出现错误计算?
由于
如果您愿意参与纯CSS实施,请查看http://matthewjamestaylor.com/blog/ultimate-multi-column-liquid-layouts-em-and-pixel-widths – 2011-06-09 01:23:49
你能提供一个[jsFiddle demo](http://jsfiddle.net/)你当前的解决方案吗?它会帮助我们回答你的问题。 – thirtydot 2011-06-09 01:25:17
@Matt。我看到了这个。我的印象是只适用于基于纯色背景色的列效果,我说得对吗? – Ben 2011-06-09 01:27:44