All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP将成为网站综合解决方案的重要角色_php资料_编程技术
详谈基于JSON的高级AJAX开发技术_.net资料_编程技术
Asp.net连接数据实例(ACCESS版)_[Asp.Net教程]
.net根据模板生成Word文件_[Asp.Net教程]
如何让你的SQL运行得更快(2)_[SQL,Server教程]
怎样正确理解.NET和SQL,Server中“空值”_.net资料_编程技术
HTML 初学者指南(10)_[Html教程]
PHP实例:用PHP实现windows风格的树型菜单_php资料_编程技术
在ASP.NET中跨页面实现多选_[Asp.Net教程]
讲述c#中的类型转换_[Asp.Net教程]
Reading number is top 10 pictures
Desktop Wallpapers1
Sell the barbecue as says father du breul4
LiXiang early youth photo
移民小国也实惠1
Is said to be a Chinese female artist fame explicit pictures before2
移民小国也实惠2
India's national beauty of the college students
人造器官和铁肺人
红楼梦金陵十二钗(1)
泳装名模阿尔贝特妮写真
Download software ranking
Unix video tutorial15
Unix video tutorial1
SP3 for SQL2000
Unix video tutorial17
The hero
WebService在.NET中的实战应用教学视频 → 第5集
Call Of Duty5
变速齿轮3.26
Professional killers2 for Android
Kung.Fu.Panda.2
归海一刀 published in(发表于) 2014/3/30 5:35:37 Edit(编辑)
用CSS解决未知高度的DIV垂直居中的问题_[Html教程]

用CSS解决未知高度的DIV垂直居中的问题_[Html教程]

用CSS解决未知高度的DIV垂直居中的问题_[Html教程]
本篇详细介绍了用CSS解决未知高度的DIV垂直居中的问题的文章主题。


原文标题:Vertical Centering in CSS
副标题:Yuhu's Definitive Solution
with Unknown Height


尽管有CSS的vertical-align特性,但是并不能有效解决未知高度的垂直居中问题(在一个DIV标签里有未知高度的文本或图片的情况下)。


标准浏览器如Mozilla, Opera, Safari等.,可将父级元素显示方式设定为TABLE(display: table;) ,内部子元素定为table-cell (display: table-cell),通过vertical-align特性使其垂直居中,但非标准浏览器是不支持的。


非标准浏览器只能在子元素里设距顶部50%,里面再套个元素距顶部-50% 来抵消。


CSS


body {padding: 0; margin: 0;}
body,html{height: 100%;}
#outer {height: 100%; overflow: hidden; position: relative;width
: 100%; background:ivory;}
#outer[id] {display: table; position: static;}
#middle {position: absolute; top: 50%;} /* for explorer only*/
#middle[id] {display: table-cell; vertical-align: middle; position
: static;}
#inner {position: relative; top: -50%;width: 400px;margin: 0 auto;}
/* for explorer only */
div.greenBorder {border: 1px solid green; background-color: ivory;}


xhtml














以上CSS代码的优点是没有hacks,采用了IE不支持的CSS2选择器#value[id]。


CSS2选择器#value[id]相当于选择器#value,但是Internet Explorer不支持这种类型的选择器。同样地.value[class],相当于.value,这些只有标准浏览器能读懂。


测试:Firefox1.5、Opera9.0、IE6.0、IE5.0通过。





 
 
 
 
 


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.