如何使用可变高度的主体制作标题/正文/页脚'弹出'div?

时间:2013-01-09 03:00:17

标签: javascript jquery css

我制作了一个弹出式div,它看起来像我网页上的经典窗口,可以最小化/调整大小/移动。

我需要它有一个25 px高的标题,一个50px高的页脚然后窗口的主体总是采用“休息”,这是可变的,因为窗口可以调整大小。这个窗口的主体动态更新DOM,可以添加元素。如果添加了足够多的元素,它们的组合高度超过了分配给窗口主体的高度,那么这个主体区域应该开始滚动,当用户滚动页脚时总是保持原位 - 它只是滚动的主体内容。 / p>

如何使用CSS,jQuery实现这一点,并且它适用于IE8?

代码看起来应该是这样的,基本上是:

<div id="wrap">
  <div id="header">
    ... 25 px high space fixed to the top
  </div>
  <div id="body">
    ... stretches to fill the space available height/width ... 
    ... scrollbars available when the body content exceeds height available ...
    ... jQuery allows user to resize the whole window, so this body should always fill ...
  </div>
  <div id="footer">
    ... 50px footer with controls, must always be fixed to bottom of window ...
    ... must never move no matter if the user scrolls the body ...
  </div>
</div>

这可以完成,以便跨浏览器工作吗? IE8 +,Firefox,Chrome?

1 个答案:

答案 0 :(得分:3)

在此尝试演示http://jsfiddle.net/XfPAG/4/。这个想法是使用绝对位置:

HTML

<div id="wrap">
  <div id="header">
    ... 25 px high space fixed to the top
  </div>
  <div id="body">
    ... stretches to fill the space available height/width ... 
    ... scrollbars available when the body content exceeds height available ...
    ... jQuery allows user to resize the whole window, so this body should always fill ...
  </div>
  <div id="footer">
    ... 50px footer with controls, must always be fixed to bottom of window ...
    ... must never move no matter if the user scrolls the body ...
  </div>
</div>

CSS:

#wrap, #header, #body, #footer {
  position: absolute;
  left: 0;
  right: 0;
}

#wrap {
  top: 0;
  bottom: 0;
}

#header {
  height: 25px;
  top: 0;
}

#footer {
  height: 50px;
  bottom: 0;
}

#body {
  top: 25px;
  bottom: 50px;
  overflow: auto;
}
相关问题