Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67841
  • 博文数量: 15
  • 博客积分: 841
  • 博客等级: 准尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 00:14
文章分类

全部博文(15)

文章存档

2011年(1)

2008年(14)

我的朋友

分类: 系统运维

2008-04-27 04:00:51

横向居中:在除IE的其他浏览器中position:relative; margin:0 auto;可以实现横向居中,而IE的怪异模型需要使用text-align:center;
纵向居中:其他浏览器中父元素使用display:table;子元素使用display:table-cell; vertical-align:middle;即可实现完美垂直居中,而IE中不支持此属性,我们必须在父元素中使用position:absolute; top:50%;子元素中使用position:relative; top:-50%;

为了写出通用的CSS代码,我们还必须使用!important(IE不支持此属性)来消除IE与其他浏览器中的差异。


   

       

       

   

html,body{text-align:center; background-color:#000000; margin:0; padding:0;}
#outer {height:100%; width:600px; overflow:hidden; position:relative;  margin:0 auto; display:table; text-align:left;}
#middle {position:static!important; position:absolute; top:50%; display:table-cell; vertical-align:middle;}
#inner {position:static!important; position:relative; top:-50%; width:600px; height:400px;}

支持的浏览器:IE7,Netscape Navigator 9,Opera 9,FireFox 2,Safari 3

阅读(413) | 评论(0) | 转发(0) |
0

上一篇:Linux系统守护进程详解

下一篇:Shell:sha-bang

给主人留下些什么吧!~~