17

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

Tag: 前端开发cnscorpio @ 17:18

前些天,利华说能不能让某个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!!

说两句吧