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

Reading number is top 10 articles
ASP.NET Remoting体系结构(八)
SQL,Server,2008,R2官方上市日期出炉_mssql学习_编程技术
简单介绍,ASP.NET,中的运算操作符_[Asp.Net教程]
SQL Server数据库恢复操作实例_[SQL Server教程]
用ASP.NET,2.0主题控制网站外观_.net资料_编程技术
SQL,Server,2005数据库产品线的扩展_[SQL,Server教程]
SQL查询语句对象化的实现(C#)_[SQL,Server教程]
Delphi以XPManifest组件显示界面
SQL,Server了解你的服务器的状态_[SQL,Server教程]
百分百的弹出窗口_JavaScript技术_编程技术
Reading number is top 10 pictures
Seductive beauty of crime2
这才是真正的人体艺术1
漂亮脸蛋魔鬼身材2
美女浴室写真1
The household of rural style is designed
Photographed the passion of the clients and prostitutes in the sex trade picture2
Kim jong il's mistress, national beauty JinYuJi actor3
人美胸美腿更美1
猫眯也疯狂
The other a successor of sora aoi
Download software ranking
Desire a peach blossom
Sora aoi‘s film--Lust fan wall
asp.net技术内幕
Such love down(擒爱记)
电脑知识及技巧大合集
jdk1.5
Unix video tutorial12
The hero
Unix video tutorial3
美女写真3
归海一刀 published in(发表于) 2014/3/30 5:20:23 Edit(编辑)
元素水平居中方案全集_[Html教程]

元素水平居中方案全集_[Html教程]

元素水平居中方案全集_[Html教程]
本篇详细介绍了元素水平居中方案全集的文章主题。


先来看我一个简单XHTML/HTML文件代码(部分),我们的目的是让#container水平居中。



content


Lorem ipsum dolor sit amet, consectetuer adipiscing elit.Phasellus varius eleifend.






使用自适应边界(auto margin)
水平居中任意元素的首选办法是使用边界(margin)性质(property),并把左右之值设置为auto。但你必须为#container指定一个宽度。


div#container {
margin-left: auto;
margin-right: auto;
width: 168px;
}
这个方案在任何当代浏览器上都有效,即使是IE6,前提是在web标准兼容模式下(compliance mode)。不幸的是,它不会在先前版本的IE/Win中工作。我们为此列一个表格:



浏览的自适应边界支持一览表 浏览器 版本 支持
Internet Explorer 6.0, compliance mode 是
Internet Explorer 6.0, quirks mode 否
Internet Explorer 5.5 Windows 否
Internet Explorer 5.0 Windows 否
Internet Explorer 5.2 Macintosh 是
Mozilla 所有当前版本 是
Mozilla Firefox 所有版本 是
Netscape 4.x 否
Netscape 6.x+ 是
Opera 6.0, 7.0 Macintosh and Windows 是
Safari 1.2 是


尽管受到浏览器支持的限制,大部分设计师还是提倡你尽可能这样做。但我们依然可以使用CSS应付一切情况。


使用文本排列(text-align)
此方案需要使用到text-align性质,应用给body元素并且赋予center的值。


body {
text-align: center;
}
它公正地对待各种浏览器,十分彻底,唾手可得。然而,这是赋予文本的性质,它使#container中的文本也居中了。所以,在布局上我们还得做一些额外工作:


div#container {
text-align: left;
}
这样才可以把文本的对齐方式返回默认状状态。


综合边界和文本排列
因为文本排列向后兼容,当代浏览器也支持自适应边界,很多设计师把他们结合起来,实现跨浏览器使用。


body {
text-align: center;
}
#container {
margin-left: auto;
margin-right: auto;
border: 1px solid red;
width: 168px;
text-align: left
}
唉,依然不完美,因为还是一个黑客技巧 (hack)。你不得不为文本排列写下多余的规则。但现在,我们可以使用更完美的跨浏览器的方案。


负边界解决方案
此方案得结合使用绝对定位(absolute positioning )。首先,把#container绝对定位并左偏移 50%,这样,#container的左边界就是页面分辨率的一半。下一步,把#container的左边界设置为负值,值大小为#container宽 度(width)的一半。


#container {
background: #ffc url(mid.jpg) repeat-y center;
position: absolute;
left: 50%;
width: 760px;
margin-left: -380px;
}
看,没有任何黑客技巧(no hacks)!连Netscape 4.x都支持!





 
 
 
 
 


添加到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.