当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS布局实例:上中下三行,中间自适应

CSS样式表
未知长宽元素在已知300px*300px的容器中垂直居中(IE6/7/8/FF)
CSS dashed和dotted的区别
css 超过宽度的文字显示点点
不同浏览器对CSS3和HTML5的支持状况
使用DIV+CSS布局网站的优点和缺陷分析
CSS样式表中的position属性详细说明
css 圆角边框
CSS 网页布局问题 li上多出的margin问题
为什么有些css样式不起作用
tab选项卡布局之利用a的一个选项形式
UL、LI 无序列表实现纯CSS网站导航菜单
在IE下,当margin:0 auto;无法使得块级元素水平居中时
IE bug input 外层浮动的边距问题
重置浏览器默认样式
两种跨浏览器的自适应高的css代码
纯CSS无hacks的跨游览器自适应高度多列布局 推荐
IE中伪类hover的使用及BUG
img与容器下边界的空隙(缝隙) 的解决方法
CSS入门篇之传智播客学习
CSS3 倾斜的网页图片库实例教程

CSS样式表 中的 CSS布局实例:上中下三行,中间自适应


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 79 ::
收藏到网摘: n/a


  上中下三行布局,上下定高,中间栏自适应浏览器高度,且内容垂直居中。
  firefox 2.0 / win ie 6/ win ie 7 /opera 8.5 cn/win safari 测试通过。
  对于非ie内核浏览器,通过设定display:table、display:table-row和display:table-cell来模拟表格的表现形式。
  最外层#box { display:table; },高度100%,其子层#header/#main/#footer为{ display:table-row; },因此可以模拟表格的行效果,上下定高,则中间不定高的层自适应高度。
  #wrap层为{ display:table-cell; }模拟单元格,因此可以设定{ vertical-align:middle; },垂直居中。
  由于Win IE不支持{ display:table; },因此,只能采取定位的方式实现。<!--[if IE]>内是针对ie的设定。
                         以下为引用的内容:
            
<!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=gb2312" />
<title>上中下三行布局,上下定高,中间栏自适应浏览器高度,且内容垂直居中</title>
<style type="text/css">
* {
margin:0;
padding:0;
}
html,
body,
#box {
height:100%;
font:small/1.5 "宋体", serif;
}
body {
text-align:center;
}
#box {
text-align:left;
background:#666;
display:table;
width:80%;
margin:0 auto;
position:relative;
}
#box > div {
display:table-row;
}
#header,
#footer {
background:#fcc;
height:50px;
}
#main {
background:#ccf;
}
#main #wrap {
display:table-cell;
background:#ffc;
vertical-align:middle;
}
#text {
text-align:center;
}
</style>
<!--[if IE]>
<style type="text/css">
#header,
#footer {
width:100%;
z-index:3;
position:absolute;
}             
#footer {
bottom:0;
}
#main {
height:100%;
z-index:1;
position:relative;
}
#main #wrap {
position:absolute;
top:50%;
width:100%;
text-align:left;
}
#main #text {
position:relative;
width:100%;
top:-50%;
background:#ccc;
}
</style>
<![endif]-->
</head>             
<body>
<div id="box">
<div id="header">header</div>
<div id="main">
<div id="wrap">
<div id="text">
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
<p>内容内容</p>
</div>
</div>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>                          

[Ctrl A 全部选择 提示:你可先修改部分代码,再按运行]