网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网页制作 > CSS
网页制作:Dreamweaver教程,FrontPages教程,Javascript教程,HTML教程,CSS教程,心得技巧,DHTML教程,网页特效,Discuz!论坛
本月文章推荐
.CSS初级入门:样式的多次声明.
.IE6不解析某些CSS代码的解决方法.
.用图片实现超级链接的个性化下划.
.CSS做一个超链接的陷下效果.
.实践DIV+CSS网页布局入门指南.
.如何将XHTML+CSS页面转换为打印机.
.第五章 文字性质的CSS .
.客户端(CSS)解决自动截取字符串长.
.鼠标经过背景变色之CSS+DIV方法.
.FF下神秘的不起作用的CSS.
.巧用CSS的Border属性.
.用CSS轻松实现网上填空.
.css技巧之PDF、ZIP、DOC链接的标.
.CSS样式表中的选择符.
.中文排版CSS心得.
.CSS中expression使用简介.
..NET 中部分常用的CSS .
.CSS仿淘宝首页导航条按钮布局效果.
.CSS 循序渐进(一)画个瓢 .
.搞定CSS SPAN和DIV的区别.

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

发表日期:2008-4-5


  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 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> 

上一篇:CSS教程关于css框架网页设计 人气:4733
下一篇:关于CSS 框架的论述 人气:3548
浏览全部CSS的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐