加入收藏 设为首页 联系站长
WEB2.0教程 | CSS教程 | HTML教程 | 设计素材 | CSS 模板 | CSS酷站欣赏 | CSS布局实例 | Javascript | 建站代码 | 专业软件 | 常见问题 | 内容搜索
>首页 -> 学习教程 -> WEB2.0教程

TOP

DivCSS布局实例:三行单列 上下固定高度 中间自适应

[ 录入者:admin | 时间:2007-12-24 02:16:42 | 作者: | 来源: | 浏览:65次 ]

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; },因此,只能采取定位的方式实现。<!--[if IE]>内是针对ie的设定。

div css xhtml xml Example Source Code Example Source Code [www.xxcss.com]
<!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>DivCSS布局实例:三行单列 上下固定高度 中间自适应</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> 

  查看最终的运行效果:

 

[上一篇]什么是Web 2.0 [下一篇]一个纯CSS+DIV的液态布局代码

评论

称  呼:
内  容:

相关栏目

最新文章

热门文章

推荐文章

相关文章

推荐浏览

中国百度网
安徽皖一月嫂家政
犯罪现场