• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

CSS+DIV自适应高度布局_css

css 搞代码 7年前 (2018-06-11) 204次浏览 已收录 0个评论

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

CSS+DIV自适应高度布局_css

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下为完美效果。

欢迎大家阅读css+DIV自适应高度布局_css》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:CSS+DIV自适应高度布局_css

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址