HTML 和 CSS 中的一切看起来都很好,因此有问题的 div 应该位于页面的中心。我在下面包含了一些代码片段,但真正的代码可以在这里找到:http://jsfiddle.net/stbx08mk/
底部的 test-div 应该位于 1024 区域的中心,但事实并非如此。为什么不呢?
#page-wrapper {
background-color: white;
margin: 0 auto;
overflow: auto;
padding: 0;
width: 1024px;
}
#test-div {
background-color: orange;
float: left;
height: 100px;
margin: 0 auto;
width: 800px;
}
最佳答案
根据您的 fiddle ,您需要将 #test-div
样式调整为 float: none;
和 clear: Both;
#test-div {
background-color: orange;
clear: both;
float: none;
height: 100px;
margin: 0 auto;
width: 800px;
}
关于html - Div 应该居中,但事实并非如此?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25331648/