网络编程
位置:首页>> 网络编程>> 网页设计>> CSS实现垂直居中的5种方法(3)

CSS实现垂直居中的5种方法(3)

作者:糖伴西红柿 来源:前端观察 发布时间:2009-03-04 12:53:00 

标签:垂直居中,方法,css,浏览器

方法三

这种方法,在 content 元素外插入一个 div。设置此 div height:50%; margin-bottom:-contentheight;。
content 清除浮动,并显示在中间。



<div id="floater"></div><div id="content"> Content here</div>



#floater {float:left; height:50%; margin-bottom:-120px;}#content {clear:both; height:240px; position:relative;}

优点:
适用于所有浏览器
没有足够空间时(例如:窗口缩小) content 不会被截断,滚动条出现

缺点:
唯一我能想到的就是需要额外的空元素了(也没那么糟,又是另外一个话题)

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com