CSS垂直居中

In this method, we will insert a div above the content element. This will be set to height:50%; and margin-bottom:-contentheight;. The content will then clear the float and end up in the middle.

<div id="floater">
<div id="content">
	Content here
</div>
</div>
#floater	{float:left; height:50%; margin-bottom:-120px;}
#content	{clear:both; height:240px; position:relative;}

THE GOODS

  • Works in all browsers
  • When there isn’t enough space (ie. the window shrinks) our content will not be cut off, and a scrollbar will appear.

THE BADS

  • Only one I can think of is that it requires an extra empty element (which isn’t that bad, another subjective topic)

One Response to “CSS垂直居中”

  1. 没有演示?光从代码上看不明白怎么会居中。。。

Leave a Reply

Key: article Value: 1
RSS訂閱

I am just beginning...

请画出自己的风格地图,自己的成长路线图,不要迷信人手一张的成功观光图,那样你永远看不到与别人不同的未来前景。

test

记一下

1. Information graphics
1. error_messages
2. messagebox设计规范
3. 客户端右键菜单的设计