我有一个 div 并希望它水平居中 - 虽然我给它 margin:0 auto;
它没有居中……
.container {
position: absolute;
top: 15px;
z-index: 2;
width:40%;
max-width: 960px;
min-width: 600px;
height: 60px;
overflow: hidden;
background: #fff;
margin:0 auto;
}
原文由 CoreDo 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要设置
left: 0
和right: 0
。这指定了从窗口边缘偏移边缘边缘的距离。
来源: http ://www.w3.org/TR/CSS2/visuren.html#position-props