Loading...
  所在位置:论坛首页 -> ┈┋电脑网络技术区┋┈ -> 网页制作技术 -> CSS上中下三行布局实例教程
标题:CSS上中下三行布局实例教程收藏 编辑 删除 楼主 | 上一篇 下一篇
兜迷儿
等级:职业侠客
权限:普通用户
积分:79
金钱:5059
声望:105
经验:105
发帖数:1299
注册:2006年8月20日
资料 短消息2008-4-20 10:56:19
CSS布局实例:上中下三行布局,上下定高,中间栏自适应浏览器高度,且内容垂直居中。本文代码在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; },因此,只能采取定位的方式实现。内是针对ie的设定。

以下是引用片段:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xml(标准化越来越近了)ns="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> 

我从来不看电视,我只不过是经常核对一下报纸上的电视节目有没有印错。

2008-4-20 10:56:19 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 商业版本 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com