我基本上使用3列布局的网站。我想实现的是将中间(内容)列的高度调整到右侧列(侧栏),以便中间列右侧的边框到达页面底部。此外,我还希望左列将其高度调整为其他列,并在页面底部填充背景图像单元。动态调整div的高度在网页上
这是我到目前为止一直在做(panel_left =背景图片左边一列,panel_right是在div内容(中柱)和侧栏(右栏)周围的div) :
function setDivHeight() {
//set height of content according to sidebar if content is smaller than sidebar
var DivHeightSidebar = document.getElementById('sidebar').offsetHeight;
var DivHeightContent = document.getElementById('content').offsetHeight;
if(DivHeightContent < DivHeightSidebar)
{
document.getElementById('content').style.height = DivHeightSidebar + 'px';
}
//set height of panel_left according to panel_right so background image reaches until bottom of page
var DivHeight = document.getElementById('panel_right').offsetHeight;
document.getElementById('panel_left').style.height = DivHeight + 'px';
}
在</body>
标记之前的每个页面上调用此函数。
问题是,有时是有效的,但有时不是。在某些情况下,内容列的高度会根据边栏列的高度进行调整,但应该更长,内容不再适合。屏幕截图:http://www.massageforum.be/Massageforum1.png
另外,有时左侧列的高度未正确调整到panel_right的高度。
我在Chrome,Firefox和Safari中看到此行为;没有测试其他浏览器。
有关如何使此功能工作更强大的任何建议?
如何改变你的网页结构?我认为用JavaScript实现这一切并不是一个好主意... – Dion