css – 位置:绝对,div下的div

前端之家收集整理的这篇文章主要介绍了css – 位置:绝对,div下的div前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有3个div,每个都有位置:绝对.

首先是标题,它的工作.

标题具有恒定的高度,第二个div“内容”也有效.

第三个div是“页脚”.

内容”具有可变高度,当“内容”高于网络浏览器窗口时,“页脚”为“内容”.无论内容高度如何,我都想在“内容”下“页脚”.

我的标题是300px高度,内容有margin-top:300px.我不能对页脚使用相同的内容,因为内容没有恒定的高度.

我不想设置一个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

原文链接:https://www.f2er.com/css/427080.html

猜你在找的CSS相关文章