* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
2、因为上面提到的问题,所以为了让布局自适应高度,我们要加上 min-height: 100%;,虽然IE不支持这个属性但是IE的 height: 100%; 有同样的作用:
#wrapper {
min-height: 100%;
}
* html #wrapper {
height: 100%;
}
这样,一个最简单的最小高度满一屏的自适应布局就做好了。为了便于查看,我加了一些宽度和背景色修饰,如下:
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
text-align: center;
font: 12px/1.4 Verdana, sans-serif;
background: #f00;
}
#wrapper {
width: 770px;
min-height: 100%;
background: #ccc;
margin: auto;
text-align: left;
}
* html #wrapper {
height: 100%;
}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>example 2</title>
<style type="text/css">
/*<![CDATA[*/
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
text-align: center;
font: 12px/1.4 Verdana, sans-serif;
background: #F00;
}
#wrapper {
width: 770px;
min-height: 100%;
background: #ccc;
margin: auto;
text-align: left;
}
* html #wrapper {
height: 100%;
}
#header {
background: Green;
height: 40px;
}
#sidebar {
float: left;
width: 200px;
background: Gray;
}
#content-box {
float: right;
width: 570px;
background: Olive;
}
#footer {
height: 50px;
background: Background;
width:770px;
margin: auto;
}
/*]]>*/
</style>
</head>
<body>
<div id="wrapper">
<div id="header">此处显示 id "header" 的内容</div>
<div id="content-box">此处显示 id "content-box" 的内容</div>
<div id="sidebar">此处显示 id "sidebar" 的内容</div>
</div>
<div id="footer">此处显示 id "footer" 的内容</div>
</body>
</html>
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|