现在的位置: 首页 >> 网页设计 >> CSS >> CSS+DIV自适应高度布局
添加时间:2006-4-6 来源:一叶千鸟 作者:
CSS+DIV自适应高度布局

要实现的是head foot固定,中间区域随内容高度自适应,拖动滚动条时foot永远居底。



SolarDreamStudios的方案给了我一个很好的思路,但关键部分是原创的,一直以为会比SolarDreamStudios的方案好,结果仔细看他们的代码,才发现其实原理都差不多,不过他们似乎在兼容性上下了更多工夫,具体未测试。

A. 宽度100%自适应

结构代码

<body>

<div id="head">head</div>
<div id="head_height"></div>

<div id="middle"></div>

<div id="foot_height"></div>
<div id="foot">foot</div>

</body>

表现代码
#head { width:100%; text-align:center; background:#FF9400; height:100px; position:absolute; top:0;}
  #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; background:#f00; height:100px; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
  #foot_height { height:100px;}


B. 宽度固定居中

结构代码
<body>

<div id="head">
  <div id="head_content">head</div>
</div>
<div id="head_height"></div>

<div id="middle"></div>

<div id="foot_height"></div>
<div id="foot">
  <div id="foot_content">foot</div>
</div>

</body>

表现代码
#head { width:100%; text-align:center; position:absolute; top:0; left:0;}
  #head_content { line-height:100px; width:700px; margin:0 auto; background:#FF9400; height:100px;}
  #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
  #foot_content { line-height:100px; width:700px; margin:0 auto; background:#f00; height:100px;}
  #foot_height { height:100px;}

测试环境IE6.0和FF1.5,IE环境下因为BUG有时会自动出现滚动条(SolarDreamStudios的方案一样),FF下为完美效果。
上一篇:高度100%的绝对定位自适应布局 下一篇:CSS+JavaScript打造超酷右键菜单
大部分文章摘自网上,如有侵犯您的权益请与我们联系,我们会第一时间进行处理,谢谢! [ 打印文章 ] [ 关闭窗口 ]
推荐文章
·利用CSS改善网站可访问性
·用CSS控制网页总体风格
·DropShadow属性、Chroma属性和bl
·CSS字型的设定
·CSS应用基础教程(1) 基本认识
·为打印输出创建一个CSS样式
·WEB设计中CSS样式表应用小技巧十
·XHTML+CSS的静态页面实现多风格
·实例详解CSS滤镜(5)DropShadow属
·实例详解CSS滤镜(10)Xray属性
相关文章
·用GoLive实现CSS+DIV之二
最新文章
·CSS制作11种风格不同的特效文字
·利用CSS改善网站可访问性
·显示/隐藏引出的CSS Bug
·网页技巧之怎样编写CSS
·CSS快速入门
·有关表格边框的css语法整理
·巧用CSS控制鼠标样式变换
·CSS实例:横线样式的输入框
·巧用CSS滤镜做图案文字
·CSS自定义属性Expression
Google