.example{ height: 200px; width: 200px; background-color: red; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px; }左右居中:
.sample{ height: 200px; width: 200px; background-color: blue; margin: 0 auto; }
.instance{ height: 200px; width: 200px; background-color: gray; position: fixed; top: 50%; margin-top: -100px; }fixed 定位相对于窗口,absolute定位相对于已经定位的父级元素(fixed,absolute,relative)。
<div style="margin:0px auto;"><div style="float:left;"></div></div>