Header 与 Footer 的 DIV 高度固定, 中间内容 DIV高度自适应,内容不满一页时,默认填满屏幕。
一、需求:
页面布局分三大块:
Header
Body
Footer
1、内容不满一页时,Footer 在屏幕最底部,Body 填充满 Header 与 Footer 中间的部分。
2、当缩小浏览器时,Footer 在底部浮动,直到碰到 Body 区域中有内容的部分为止。
3、当 Body 里的内容大于一页时,以正常出现滚动条的方式。
二、方法:
1、页面填充满屏幕。
1.1、先去掉所有元素的边距。
* {
margin:;
padding:;
}
1.2、设置页面高度 100%,并设置为 overflow: hidden,即:超多的部分不显示;
#wrapper {
overflow: hidden;
_height: 100%;
height: auto !important;
min-height: 100%;
}
1.3、内容区域设置成如下:
#body {
padding-bottom: 32767px;
margin-bottom: -32767px;
}
内容区域当内容不满一页时,自动高度 100%完成~并且不会因此出现将内容吞掉或者页面错乱问题。
2、Footer 区域当内容不满一页时,自动浮动在页面最底部,并且收缩浏览器大小时,会随着浏览器的缩小而一直浮动在浏览器底部,直到碰到存在内容的位置时停止浮动,当Footer超出一页时,与正常 DIV 一样在页面最下面。
2.1、在 wrapper DIV里加上 position: relative;
#wrapper {
overflow: hidden;
_height: 100%;
height: auto !important;
min-height: 100%;
position: relative;
background-color: blanchedalmond;
}
2.2、在内容里 body 区域增加子DIV ”body-wrapper“,并设置如下:
#body-wrapper {
padding-bottom: 100px;
}
2.3、在 Footer 区域设置相对位置。
#footer {
width: 100%;
height: 100px;
background-color: #d9d9d9;
position: absolute;
bottom: 0px;
}
完成!
完整代码如下:
CSS:
整体:
* {
margin:;
padding:;
}
html, body {
height: 100%;
}
#wrapper {
overflow: hidden;
_height: 100%;
height: auto !important;
min-height: 100%;
position: relative;
background-color: blanchedalmond;
}
头部:
#header {
width: 990px;
height: 90px;
margin: 0px auto;
background-color: white;
}
内容:
#body {
width: 990px;
margin: 0 auto;
padding-bottom: 32767px;
margin-bottom: -32767px;
background-color: aliceblue;
}
#body-wrapper {
padding-bottom: 100px;
}
底部:
#footer {
width: 100%;
height: 100px;
background-color: #d9d9d9;
position: absolute;
bottom: 0px;
}
#footer-wrapper {
width: 990px;
margin: 10px auto;
color: #6e6e6e;
}
#footer-left{
float:left;
}
#footer-right{
float:right;
}
#footer a{
color: #6e6e6e;
}
页面:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<title>我的 ASP.NET MVC 应用程序</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" /> <link href="/Content/Default/Site.css" rel="stylesheet"/>
<link href="/Content/Default/Header.css" rel="stylesheet"/>
<link href="/Content/Default/Body.css" rel="stylesheet"/>
<link href="/Content/Default/Footer.css" rel="stylesheet"/> </head>
<body>
<div id="wrapper">
<div id="header">
123456
</div>
<div id="body">
<div id="body-wrapper">
...
</div>
</div>
<div id="footer">
<div id="footer-wrapper">
<div id="footer-left">
<a href="#">关于我们</a> | <a href="#">友情链接</a> | <a href="#">免责声明</a>
</div>
<div id="footer-right">
Copyright ©
</div>
</div>
</div>
</div>
</body>
</html>
Header 与 Footer 的 DIV 高度固定, 中间内容 DIV高度自适应,内容不满一页时,默认填满屏幕。的更多相关文章
- xHTML+div布局:三个div,两边div宽度固定,中间div宽度自适应
xHTML+div经常考题:三个div,两边div宽度固定,中间div宽度自适应. 和大家分享一个实现方式: 1.html代码 <div class="dyleft"> ...
- 父级div宽度100%,子级一个div宽度固定,另一个宽度自适应
<!DOCTYPE html> <html> <head> <title>布局测试</title> <style type=" ...
- 两个DIV,左DIV宽度固定,右DIV自动填满剩余空间
<style type="text/css"> #main{ width:98%; } #sidebar{ float:left; width:200px; backg ...
- JavaScript中,让一个div在固定的父div中任意拖动
1.css代码 #big { border: 1px solid #FF3300; width: 300px; height: 300px; position: relative; } #small ...
- easy Html5 - Jquery Mobile之ToolBars(Header and Footer)
jquery 在web js框架上的风暴还在继续却也随着移动终端走向了mobile:那么jquery mobile到底包括些什么呢 简介工具栏是在移动网站和应用中的头部,尾部或者内容中的工具条:Jqu ...
- ## GridView 布局:item设置的高度和宽度不起作用、自动适配列数、添加Header和Footer ##
一.item设置的高度和宽度不起作用 转自:http://www.cnblogs.com/0616--ataozhijia/p/6031875.html [Android Pro] listView和 ...
- 布局:上下两个div高度固定,中间自适应
需求:经典布局 —— 头尾固定高度中间高度自适应布局 头部固定高度,宽度100%自适应父容器: 底部固定高度,宽度100%自适应父容器: 中间是主体部分,自动填满,浏览器可视区域剩余部分,内容超出则中 ...
- HTML中--定义header和footer高度中间自适应
<html> <head> <meta charset="utf-8" /> <title></title> <s ...
- css样式实现左边的固定宽度和高度的图片或者div跟随右边高度不固定的文字或者div垂直居中(文字高度超过图片,图片跟随文字居中,反之文字跟随图片居中非table实现)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- Hadoop2.0新特性-持续追加【干货】
1.NAME NODE HA 2.NAME NODE Federation 3.HDFS 快照(目录快照) 4.HDFS 缓存 5.HDFS ACL 6.异构层级存储结构 -------------- ...
- django form关于clean及cleaned_data的说明 以及4种初始化
1.form类的运行顺序是init,clean,validte,save其中clean和validate会在form.is_valid()方法中被先后调用.(这里留有一个疑问,结构完全相同的两个f ...
- CentOS6 root 用户 vi/vim 无法开启高亮
编辑 /etc/profile.d/vim.sh if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n &quo ...
- 第二百五十九天 how can I 坚持
晚上,弟弟给我说了下他前几天发生的事,这孩子,有事就不知道说下,自己闷在心里. 刘松打算最近买房了,弟弟和建哥也考虑买,让他俩商量着来吧,早晚都得买. 有点揪心.想结婚不知道该和谁结... 睡觉.烦.
- 基于 Red5 的流媒体服务器的搭建和应用
http://www.ibm.com/developerworks/cn/opensource/os-cn-Red5/ Red5 是一个采用 Java 开发的开源免费 Flash 流媒体服务器.Red ...
- Spring入门(5)-自动装配Bean属性
Spring入门(5)-自动装配Bean属性 本文介绍如何装配Bean属性. 0. 目录 ByName ByType constructor 默认自动装配 混合使用自动装配和显示装配 1. ByNam ...
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)
题意:略. 析:首先是假设前n-2个已经放好了,那么放第 n 个时,先考虑一下第 n-1 放的是什么,那么有两种情况. 如果n-1放的是和第1个一样的,那么第 n 个就可以在n-2的基础上放2个,也就 ...
- jq倒计时
var referTime = 5; setInterval("refer('#show')", 1000); function refer(obj){ if(referTime ...
- Castle ActiveRecord学习实践
Castle是针对.NET平台的一个开源项目,从数据访问框架ORM到IOC容器,再到WEB层的MVC框架.AOP,基本包括了整个开发过程中的所有东西,为我们快速的构建企业级的应用程序提供了很好的服务. ...
- SQLite数据库连接方式
http://blog.csdn.net/ZF101201/archive/2010/05/26/5626365.aspx SQLite.NET Type: .NET Framework Cla ...