时间:2021-05-08
上中下三行布局,上下定高,中间栏自适应浏览器高度,且内容垂直居中。
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>
<!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 全部选择 提示:你可先修改部分代码,再按运行]
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
CSS两列布局,右侧固定,左侧自适应宽度这是右侧的内容这是左侧的内容,自适应宽度CSS两列布局,左侧固定,右侧自适应宽度中间内容,自适应宽度CSS三列布局,左右
独行DIV自适应宽度布局CSS实例与扩大应用范围DIVCSS5先给大家介绍独立一列自适应宽度,也就是单独一行宽度自适应DIV的布局。通过DIVCSS实例CS
本文实例讲述了纯CSS实现的三列布局网页效果。分享给大家供大家参考。具体分析如下:这是一个比较常用的用DIV+CSS布局的网页,包括头部、中间、一行三列布局、导
最近在做一个自适应布局的项目,所以学了下自适应,下面是总结。此总结只做效果,不关注效率和代码优化。1.css3html中添加复制代码代码如下:css中的整体布局
一个普通的自适应显示的三栏网页,当用不同的终端来查看这个页面时,会根据几种线端来显示不同的样式。在电脑上是三列,在iPad上也应该是三列,在大屏手机上是三行,在