Cnscorpio

{夫君子之所取者远,则必有所待;所就者大,则必有所忍!}

左右,垂直居中的一个例子

前些天,利华说能不能让某个div或者其他块元素左右,及垂直居中,我想了一会,做了下面这个测试页面,在IE系列,FF,safari,opera下均通过。。主要是position的用法。。其实像很多light box使用的也是类似的方法:
css:

#bd{position:static;display:table-cell;}
#test{width:500px;height:500px;background:#DADADA;position:absolute;top:50%;left:50%;
margin-left:-250px;margin-top:-250px;}

structure:

<body id="bd">
	<div id="test"></div>
</body>

demo here!!

Tips:You can change the code before run.

  1. martilo says:

    我也遇到了图片和文字要求同列居中对齐的问题!
    有待大师解决!
    明天上班向你请教!

  2. cnscorpio says:

    共同学习。。

说两句吧:
(*)
(*绝对不给酒吧女)