如何居中一个浮动的元素()

// 第一种方法不知道元素的宽高 #div{ position: absolute; width: 200px; height: 200px; margin: 0; left: 0; right: 0; top: 0; bottom: 0; } // 第二种方法知道元素的宽高 #div{ position: absolute; width: 200px; height: 200px; top: 50%; left: 50%; margin-left: -100px; margin-top: -100px; }

    推荐阅读