当前位置:首页 » htmlCSS » div css 高度 宽度 自适应浏览器 屏幕大小
div css 高度 宽度 自适应浏览器 屏幕大小
来自:thinksnet时间:2012-04-01 20:51:46
代码下载

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DIV布局——IT北瓜原创</title>
<style type="text/css">
html,body{
font: 100% 微软雅黑, 宋体, 新宋体;
margin: 0; /* 最好将 body 元素的边距和填充设置为 0 以覆盖不同的浏览器默认值 */
padding: 0;
text-align: center; /* 在 IE 5* 浏览器中,这会将容器居中。文本随后将在 #container 选择器中设置为默认左对齐 */
color: #FFF;
height: 100%; /*这里将高度设置为100%是这个布局实现自适应高度的关键,只有这里设置了高度,下面div的高度设置才起作用*/
background-color: #000;
}
#layout {
width: 100%;
height: 100%;
margin: 0px auto;
}
#header {
height: 13%;
background-color: #09F;
}
#container {
height: 82%;
background-color: #CC3;
}
#container #sidebar {
height: 100%;
width: 20%;
background-color: #C03;
float: left;
}
#container #main {
height: 100%;
width: 80%;
background-color: #CFC;
float: left;
}
#footer {
height: 5%;
background-color: #930;
}
.clearfloat { /* 此类应当放在 div 或 break 元素上,而且该元素应当是完全包含浮动的容器关闭之前的最后一个元素 */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
</style>
</head>

<body>
<div id="layout">
<div id="header">

</div>
<div id="container">
<div id="sidebar">
</div>
<div id="main">
</div>
<br class="clearfloat" />
</div>
<div id="footer">

</div>
</div>
</body>
</html>
关键词:css