建站学习网,专业提供各类建站教程,网页素材,SEO资讯等建站资源!

网站模板_网站源码_网站素材_建站教程_建站学习网

当前位置:建站学习网 > DIV+CSS教程 > CSS布局实例 >

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

更新时间:2017-01-05整理编辑:建站学习网阅读:0

上中下三行布局,上下定高,中间栏自适应浏览器高度,且内容垂直居中。

 

 

  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>

 

 

本文网址:https://www.dedexuexi.com/divcss/bj/2034.html

本站部分文章搜集与网络,如有侵权请联系本站,转载请说明出处。

标签:前端
收藏此文 赞一下!() 打赏本站

如本文对您有帮助,就请建站学习网抽根烟吧!

支付宝打赏
微信打赏
CSS table 单行布局示例代码
« 上一篇2017年01月05日
CSS文章列表切换选项卡效果实例
2017年01月05日下一篇 »
  • CSS Wave滤镜用法示例
    0阅读
    CSS Wave滤镜可能很多朋友并不喜欢用,其实用的好了,可以有不少奇异效果。CSS Wave滤镜可把对象按垂直方向叠加波形样式,使对象年上去像波浪一样。语法示例:filter:wave(add=add,freq=freq,lightst
  • CSS写的简单表格示例
    0阅读
    使用CSS写表格,不要有所怀疑,主要是对html结构进行css样式重定义,大家可以看看效果图,个人感觉还不错,感兴趣的朋友可以参考下 复制代码 代码如下: !DOCTYPE HTML html head meta http-equiv=Conte
  • 纯CSS代码实现翻页
    0阅读
    !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 xml:la...
  • 表格列表偶数列、奇数列的CSS样式示例
    0阅读
    表格列表CSS样式包括:偶数列、奇数列、鼠标经过时样式、标题列等等,在接下来的示例中将为大家完美呈现,感兴趣的朋友不要错过 HTML示例源代码: 复制代码 代码如下: table class=list_table
  • 用CSS3创建一个旋转可变色按钮
    0阅读
    先从HTML: div a class=button旋转按钮/a /div 和现在的CSS: .button { background:#aaa; color:#555; font-weight:bold; font-size:15px; padding:10px 15px; border:none...
 
QQ在线咨询