css - div 下的位置 : absolute, div

标签 css

我有 3 个 div,每个都有 position: absolute

首先是标题及其工作。

标题的高度不变,第二个 div“内容”也有效。

第三个 div 是“页脚”。

“内容”的高度可变,当“内容”高于网络浏览器窗口时,“页脚”处于“内容”状态。无论内容高度如何,我都想在“内容”下添加“页脚”。

我的标题是 300px 高度,内容有 margin-top: 300px。我不能对页脚使用同样的方法,因为内容的高度不是固定的。

我不想用 position: absolute 设置一个 div,而这 3 个 div 放在这个里面。

div#header{
  width: 960px;
  height: 200px;
  left: 50%;
  margin-left: -480px;
  position: absolute;
 }

div#content{
 width: 960px;
 border: 1px solid black;
 left: 50%;
 margin-left: -480px;
 position: absolute;
 margin-top: 200px;
 }

div#footer{
  width: 960px;
  height: 30px;
  left: 50%;
  margin-left: -480px;
  position: absolute;
  bottom: 10px; /*with this i've div fixed to the bottom of web-browsers' window */
  clear: both;
  }

最佳答案

你定位过度了。

除非您不共享某些内容,否则您无需绝对定位所有内容。

JSBin Example

关于css - div 下的位置 : absolute, div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8531323/

相关文章:

javascript - 手动编辑 "Thumbnail grid with expanding preview"的html/更改.js?

html - 如何在 div 布局上对齐标签

CSS3 webkit 在工具提示中淡入淡出

css - 使用 ui-router 的全屏背景图片

html - 有没有在复制到 Word 时保留颜色格式的 Web 开发应用程序?

css - 选择 Font Awesome 图标时更改其颜色

html - Sinatra 的 CSS 响应时间慢

javascript - 增加 Bootstrap 折叠菜单高度(打开时)

css - 为 prime faces Accordion 面板添加边框

javascript - 在不加载新页面的情况下更改 url