方法一.element { 600px; height: 400px; position: absolute; left: 0; top: 0; right: 0; bottom: 0; margin: auto; /* 有了这个就自动居中了 */ }
方法二 .element{ 100px; position: absolute; left: 50%; margin-left: -50px; } 2个方法都需要有个宽度